Skip to content

Commit a756ee1

Browse files
committed
feat: Enhance import handling and add comprehensive local import tests
1 parent d2aee6f commit a756ee1

File tree

7 files changed

+652
-10
lines changed

7 files changed

+652
-10
lines changed

src/Config/Import/ImportParserPlugin.php

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public function updateConfig(array $config, string $rootPath): array
5050
return $config;
5151
}
5252

53+
if (!\is_array($config['import'])) {
54+
$this->logger?->warning('Invalid import configuration', [
55+
'config' => $config['import'],
56+
]);
57+
58+
return $config;
59+
}
60+
5361
$this->logger?->debug('Processing imports', [
5462
'rootPath' => $rootPath,
5563
'importCount' => \count($config['import']),
@@ -61,6 +69,7 @@ public function updateConfig(array $config, string $rootPath): array
6169
foreach ($processedConfig->imports as $import) {
6270
$this->registry->register($import);
6371
}
72+
6473
$this->logger?->debug('Imports processed successfully');
6574

6675
return $processedConfig->config;

src/Config/Import/ImportRegistry.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ public function getItems(): array
4141

4242
public function jsonSerialize(): array
4343
{
44-
return [
45-
'imports' => $this->imports,
46-
];
44+
return $this->imports;
4745
}
4846

4947
public function getIterator(): \Traversable

src/Config/Import/ImportResolver.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ private function processSingleImport(
251251
'type' => $sourceConfig->getType(),
252252
'error' => $e->getMessage(),
253253
]);
254-
255-
throw $e;
254+
// Ignore the error if the import is broken
256255
} finally {
257256
// Always end processing to maintain stack integrity
258257
$this->detector->endProcessing($importId);

src/Console/GenerateCommand.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function __invoke(Container $container, DirectoriesInterface $dirs): int
127127
$config = new ConfigRegistryAccessor($loader->load());
128128

129129
$imports = $config->getImports();
130-
if ($imports !== null) {
130+
if ($imports !== null && !$this->asJson) {
131131
$renderer->renderImports($imports);
132132
}
133133

@@ -167,6 +167,8 @@ public function __invoke(Container $container, DirectoriesInterface $dirs): int
167167
'status' => 'success',
168168
'message' => 'Documents compiled successfully',
169169
'result' => $result,
170+
'imports' => $imports,
171+
'prompts' => $config->getPrompts(),
170172
]));
171173
} else {
172174
$this->output->writeln('');

src/McpServer/Prompt/PromptRegistry.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ public function getItems(): array
8686

8787
public function jsonSerialize(): array
8888
{
89-
// Only serialize regular prompts, not templates
90-
return [
91-
'prompts' => $this->getItems(),
92-
];
89+
return $this->getItems();
9390
}
9491

9592
public function getIterator(): \Traversable

tests/src/Feature/Console/GenerateCommand/CompilingResult.php

+26
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ public function assertNoDocumentsToCompile(): self
4141
return $this;
4242
}
4343

44+
public function assertMissedContext(string $document): self
45+
{
46+
foreach ($this->result['result'] as $documentData) {
47+
if ($documentData['context_path'] === $document) {
48+
TestCase::fail(\sprintf('Context file [%s] found', $document));
49+
}
50+
}
51+
52+
return $this;
53+
}
54+
4455
public function assertContext(string $document, array $contains, array $notContains = []): self
4556
{
4657
foreach ($this->result['result'] as $documentData) {
@@ -81,6 +92,21 @@ public function assertContext(string $document, array $contains, array $notConta
8192
return $this;
8293
}
8394

95+
public function assertImported(string $path, string $type): self
96+
{
97+
TestCase::assertEquals('success', $this->result['status'] ?? null, 'Status should be success');
98+
99+
foreach ($this->result['imports'] ?? [] as $import) {
100+
if ($import['path'] === $path && $import['type'] === $type) {
101+
return $this;
102+
}
103+
}
104+
105+
TestCase::fail(\sprintf('Import [%s] with type [%s] not found', $path, $type));
106+
107+
return $this;
108+
}
109+
84110
public function assetFiledToLoadConfig(): self
85111
{
86112
TestCase::assertEquals('error', $this->result['status'] ?? null, 'Status should be error');

0 commit comments

Comments
 (0)