sofia-cli 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/agents/copilot-instructions.md +39 -0
- package/.github/agents/speckit.analyze.agent.md +184 -0
- package/.github/agents/speckit.checklist.agent.md +294 -0
- package/.github/agents/speckit.clarify.agent.md +181 -0
- package/.github/agents/speckit.constitution.agent.md +84 -0
- package/.github/agents/speckit.implement.agent.md +135 -0
- package/.github/agents/speckit.plan.agent.md +90 -0
- package/.github/agents/speckit.specify.agent.md +258 -0
- package/.github/agents/speckit.tasks.agent.md +137 -0
- package/.github/agents/speckit.taskstoissues.agent.md +30 -0
- package/.github/copilot-instructions.md +257 -0
- package/.github/prompts/speckit.analyze.prompt.md +3 -0
- package/.github/prompts/speckit.checklist.prompt.md +3 -0
- package/.github/prompts/speckit.clarify.prompt.md +3 -0
- package/.github/prompts/speckit.constitution.prompt.md +3 -0
- package/.github/prompts/speckit.implement.prompt.md +3 -0
- package/.github/prompts/speckit.plan.prompt.md +3 -0
- package/.github/prompts/speckit.specify.prompt.md +3 -0
- package/.github/prompts/speckit.tasks.prompt.md +3 -0
- package/.github/prompts/speckit.taskstoissues.prompt.md +3 -0
- package/.github/workflows/ci.yml +38 -0
- package/.prettierrc +6 -0
- package/.specify/memory/constitution.md +181 -0
- package/.specify/scripts/bash/check-prerequisites.sh +166 -0
- package/.specify/scripts/bash/common.sh +156 -0
- package/.specify/scripts/bash/create-new-feature.sh +297 -0
- package/.specify/scripts/bash/setup-plan.sh +61 -0
- package/.specify/scripts/bash/update-agent-context.sh +810 -0
- package/.specify/templates/agent-file-template.md +28 -0
- package/.specify/templates/checklist-template.md +40 -0
- package/.specify/templates/constitution-template.md +50 -0
- package/.specify/templates/plan-template.md +113 -0
- package/.specify/templates/spec-template.md +115 -0
- package/.specify/templates/tasks-template.md +251 -0
- package/.vscode/mcp.json +42 -0
- package/.vscode/settings.json +19 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/LICENSE +21 -0
- package/README.md +213 -0
- package/dist/src/cli/developCommand.js +240 -0
- package/dist/src/cli/directCommands.js +143 -0
- package/dist/src/cli/envLoader.js +16 -0
- package/dist/src/cli/exportCommand.js +53 -0
- package/dist/src/cli/index.js +203 -0
- package/dist/src/cli/ioContext.js +109 -0
- package/dist/src/cli/preflight.js +57 -0
- package/dist/src/cli/statusCommand.js +110 -0
- package/dist/src/cli/workshopCommand.js +400 -0
- package/dist/src/develop/checkpointState.js +86 -0
- package/dist/src/develop/codeGenerator.js +319 -0
- package/dist/src/develop/dynamicScaffolder.js +226 -0
- package/dist/src/develop/githubMcpAdapter.js +122 -0
- package/dist/src/develop/index.js +15 -0
- package/dist/src/develop/mcpContextEnricher.js +195 -0
- package/dist/src/develop/pocScaffolder.js +542 -0
- package/dist/src/develop/ralphLoop.js +659 -0
- package/dist/src/develop/templateRegistry.js +364 -0
- package/dist/src/develop/testRunner.js +202 -0
- package/dist/src/logging/logger.js +58 -0
- package/dist/src/loop/conversationLoop.js +227 -0
- package/dist/src/loop/phaseSummarizer.js +87 -0
- package/dist/src/mcp/mcpManager.js +267 -0
- package/dist/src/mcp/mcpTransport.js +391 -0
- package/dist/src/mcp/retryPolicy.js +47 -0
- package/dist/src/mcp/webSearch.js +254 -0
- package/dist/src/phases/contextSummarizer.js +101 -0
- package/dist/src/phases/discoveryEnricher.js +156 -0
- package/dist/src/phases/phaseExtractors.js +222 -0
- package/dist/src/phases/phaseHandlers.js +328 -0
- package/dist/src/prompts/design.md +51 -0
- package/dist/src/prompts/develop-boundary.md +51 -0
- package/dist/src/prompts/develop.md +111 -0
- package/dist/src/prompts/discover.md +58 -0
- package/dist/src/prompts/ideate.md +56 -0
- package/dist/src/prompts/plan.md +51 -0
- package/dist/src/prompts/promptLoader.js +167 -0
- package/dist/src/prompts/promptLoader.ts +198 -0
- package/dist/src/prompts/select.md +47 -0
- package/dist/src/prompts/summarize/README.md +8 -0
- package/dist/src/prompts/summarize/design-summary.md +37 -0
- package/dist/src/prompts/summarize/develop-summary.md +25 -0
- package/dist/src/prompts/summarize/ideate-summary.md +27 -0
- package/dist/src/prompts/summarize/plan-summary.md +27 -0
- package/dist/src/prompts/summarize/select-summary.md +21 -0
- package/dist/src/prompts/system.md +28 -0
- package/dist/src/sessions/exportPaths.js +22 -0
- package/dist/src/sessions/exportWriter.js +406 -0
- package/dist/src/sessions/sessionManager.js +81 -0
- package/dist/src/sessions/sessionStore.js +65 -0
- package/dist/src/shared/activitySpinner.js +91 -0
- package/dist/src/shared/copilotClient.js +129 -0
- package/dist/src/shared/data/cards.json +1249 -0
- package/dist/src/shared/data/cardsLoader.js +51 -0
- package/dist/src/shared/errorClassifier.js +120 -0
- package/dist/src/shared/events.js +28 -0
- package/dist/src/shared/markdownRenderer.js +34 -0
- package/dist/src/shared/schemas/session.js +265 -0
- package/dist/src/shared/tableRenderer.js +20 -0
- package/dist/src/vendor/chalk.js +2 -0
- package/dist/src/vendor/cli-table3.js +3 -0
- package/dist/src/vendor/commander.js +2 -0
- package/dist/src/vendor/marked-terminal.js +3 -0
- package/dist/src/vendor/marked.js +2 -0
- package/dist/src/vendor/ora.js +2 -0
- package/dist/src/vendor/pino.js +2 -0
- package/dist/src/vendor/zod.js +2 -0
- package/dist/tests/e2e/developE2e.spec.js +126 -0
- package/dist/tests/e2e/developFailureE2e.spec.js +247 -0
- package/dist/tests/e2e/developPty.spec.js +75 -0
- package/dist/tests/e2e/discoveryWebSearchRelevance.spec.js +84 -0
- package/dist/tests/e2e/harness.spec.js +83 -0
- package/dist/tests/e2e/mcpLive.spec.js +120 -0
- package/dist/tests/e2e/newSession.e2e.spec.js +177 -0
- package/dist/tests/e2e/ralphLoopEnrichmentComparison.spec.js +62 -0
- package/dist/tests/e2e/workiqEnrichment.spec.js +56 -0
- package/dist/tests/e2e/zavaSimulation.spec.js +452 -0
- package/dist/tests/fixtures/test-fixture-project/src/add.js +3 -0
- package/dist/tests/fixtures/test-fixture-project/tests/failing.test.js +6 -0
- package/dist/tests/fixtures/test-fixture-project/tests/hanging.test.js +8 -0
- package/dist/tests/fixtures/test-fixture-project/tests/passing.test.js +10 -0
- package/dist/tests/fixtures/test-fixture-project/vitest.config.js +6 -0
- package/dist/tests/integration/autoStartConversation.spec.js +138 -0
- package/dist/tests/integration/defaultCommand.spec.js +147 -0
- package/dist/tests/integration/directCommandNonTty.spec.js +224 -0
- package/dist/tests/integration/directCommandTty.spec.js +151 -0
- package/dist/tests/integration/discoveryEnrichmentFlow.spec.js +175 -0
- package/dist/tests/integration/exportArtifacts.spec.js +202 -0
- package/dist/tests/integration/exportFallbackFlow.spec.js +99 -0
- package/dist/tests/integration/mcpDegradationFlow.spec.js +190 -0
- package/dist/tests/integration/mcpTransportFlow.spec.js +139 -0
- package/dist/tests/integration/newSessionFlow.spec.js +343 -0
- package/dist/tests/integration/pocGithubMcp.spec.js +186 -0
- package/dist/tests/integration/pocLocalFallback.spec.js +171 -0
- package/dist/tests/integration/pocScaffold.spec.js +163 -0
- package/dist/tests/integration/ralphLoopFlow.spec.js +359 -0
- package/dist/tests/integration/ralphLoopPartial.spec.js +368 -0
- package/dist/tests/integration/resumeAndBacktrack.spec.js +247 -0
- package/dist/tests/integration/spinnerLifecycle.spec.js +220 -0
- package/dist/tests/integration/summarizationFlow.spec.js +115 -0
- package/dist/tests/integration/testRunnerReal.spec.js +52 -0
- package/dist/tests/integration/webSearchAgent.spec.js +128 -0
- package/dist/tests/live/copilotSdkLive.spec.js +107 -0
- package/dist/tests/live/zavaFullWorkshop.spec.js +392 -0
- package/dist/tests/setup/loadEnv.js +3 -0
- package/dist/tests/unit/cli/developCommand.spec.js +567 -0
- package/dist/tests/unit/cli/directCommands.spec.js +279 -0
- package/dist/tests/unit/cli/envLoader.spec.js +58 -0
- package/dist/tests/unit/cli/ioContext.spec.js +119 -0
- package/dist/tests/unit/cli/preflight.spec.js +108 -0
- package/dist/tests/unit/cli/statusCommand.spec.js +111 -0
- package/dist/tests/unit/cli/workshopClientFallback.spec.js +80 -0
- package/dist/tests/unit/cli/workshopCommand.spec.js +329 -0
- package/dist/tests/unit/config/vitestEnvSetup.spec.js +13 -0
- package/dist/tests/unit/develop/checkpointState.spec.js +315 -0
- package/dist/tests/unit/develop/codeGenerator.spec.js +355 -0
- package/dist/tests/unit/develop/githubMcpAdapter.spec.js +231 -0
- package/dist/tests/unit/develop/mcpContextEnricher.spec.js +433 -0
- package/dist/tests/unit/develop/outputValidator.spec.js +119 -0
- package/dist/tests/unit/develop/pocScaffolder.spec.js +353 -0
- package/dist/tests/unit/develop/ralphLoop.spec.js +1248 -0
- package/dist/tests/unit/develop/templateRegistry.spec.js +85 -0
- package/dist/tests/unit/develop/testRunner.spec.js +249 -0
- package/dist/tests/unit/infraBicep.spec.js +92 -0
- package/dist/tests/unit/infraDeploy.spec.js +82 -0
- package/dist/tests/unit/infraTeardown.spec.js +63 -0
- package/dist/tests/unit/logging/logger.spec.js +43 -0
- package/dist/tests/unit/loop/conversationLoop.spec.js +592 -0
- package/dist/tests/unit/loop/phaseSummarizer.spec.js +141 -0
- package/dist/tests/unit/loop/streamingMarkdown.spec.js +147 -0
- package/dist/tests/unit/mcp/mcpManager.spec.js +279 -0
- package/dist/tests/unit/mcp/mcpTransport.spec.js +529 -0
- package/dist/tests/unit/mcp/retryPolicy.spec.js +218 -0
- package/dist/tests/unit/mcp/timeoutValidation.spec.js +46 -0
- package/dist/tests/unit/mcp/webSearch.spec.js +567 -0
- package/dist/tests/unit/phases/contextSummarizer.spec.js +140 -0
- package/dist/tests/unit/phases/discoveryEnricher.repeatCalls.spec.js +93 -0
- package/dist/tests/unit/phases/discoveryEnricher.spec.js +411 -0
- package/dist/tests/unit/phases/phaseExtractors.spec.js +352 -0
- package/dist/tests/unit/phases/phaseHandlers.spec.js +425 -0
- package/dist/tests/unit/prompts/promptLoader.spec.js +118 -0
- package/dist/tests/unit/schemas/pocSchemas.spec.js +412 -0
- package/dist/tests/unit/schemas/session.spec.js +257 -0
- package/dist/tests/unit/sessions/exportPaths.spec.js +31 -0
- package/dist/tests/unit/sessions/exportWriter.spec.js +655 -0
- package/dist/tests/unit/sessions/sessionManager.spec.js +151 -0
- package/dist/tests/unit/sessions/sessionStore.spec.js +116 -0
- package/dist/tests/unit/shared/activitySpinner.spec.js +175 -0
- package/dist/tests/unit/shared/cardsLoader.spec.js +76 -0
- package/dist/tests/unit/shared/copilotClient.spec.js +155 -0
- package/dist/tests/unit/shared/errorClassifier.spec.js +131 -0
- package/dist/tests/unit/shared/events.spec.js +55 -0
- package/dist/tests/unit/shared/markdownRenderer.spec.js +35 -0
- package/dist/tests/unit/shared/markdownRendererChunks.spec.js +70 -0
- package/dist/tests/unit/shared/tableRenderer.spec.js +34 -0
- package/dist/vitest.config.js +14 -0
- package/dist/vitest.live.config.js +18 -0
- package/docs/README.md +35 -0
- package/docs/architecture.md +169 -0
- package/docs/cli-usage.md +207 -0
- package/docs/environment.md +66 -0
- package/docs/export-format.md +146 -0
- package/docs/session-model.md +113 -0
- package/eslint.config.js +35 -0
- package/infra/deploy.sh +193 -0
- package/infra/gather-env.sh +211 -0
- package/infra/main.bicep +90 -0
- package/infra/main.bicepparam +18 -0
- package/infra/resources.bicep +134 -0
- package/infra/teardown.sh +114 -0
- package/package.json +63 -0
- package/specs/001-cli-workshop-rebuild/checklists/requirements.md +35 -0
- package/specs/001-cli-workshop-rebuild/contracts/cli.md +59 -0
- package/specs/001-cli-workshop-rebuild/contracts/export-summary-json.md +23 -0
- package/specs/001-cli-workshop-rebuild/contracts/session-json.md +30 -0
- package/specs/001-cli-workshop-rebuild/data-model.md +210 -0
- package/specs/001-cli-workshop-rebuild/plan.md +361 -0
- package/specs/001-cli-workshop-rebuild/quickstart.md +83 -0
- package/specs/001-cli-workshop-rebuild/research.md +116 -0
- package/specs/001-cli-workshop-rebuild/spec.md +240 -0
- package/specs/001-cli-workshop-rebuild/tasks.md +476 -0
- package/specs/002-poc-generation/contracts/poc-output.md +172 -0
- package/specs/002-poc-generation/contracts/ralph-loop.md +113 -0
- package/specs/002-poc-generation/data-model.md +172 -0
- package/specs/002-poc-generation/plan.md +109 -0
- package/specs/002-poc-generation/quickstart.md +97 -0
- package/specs/002-poc-generation/research.md +786 -0
- package/specs/002-poc-generation/spec.md +81 -0
- package/specs/002-poc-generation/tasks-fix.md +198 -0
- package/specs/002-poc-generation/tasks.md +252 -0
- package/specs/003-mcp-transport-integration/checklists/requirements.md +37 -0
- package/specs/003-mcp-transport-integration/contracts/context-enricher.md +220 -0
- package/specs/003-mcp-transport-integration/contracts/discovery-enricher.md +267 -0
- package/specs/003-mcp-transport-integration/contracts/github-adapter.md +149 -0
- package/specs/003-mcp-transport-integration/contracts/mcp-transport.md +288 -0
- package/specs/003-mcp-transport-integration/data-model.md +326 -0
- package/specs/003-mcp-transport-integration/plan.md +114 -0
- package/specs/003-mcp-transport-integration/quickstart.md +311 -0
- package/specs/003-mcp-transport-integration/research.md +395 -0
- package/specs/003-mcp-transport-integration/spec.md +234 -0
- package/specs/003-mcp-transport-integration/tasks.md +324 -0
- package/specs/003-next-spec-gaps.md +150 -0
- package/specs/004-dev-resume-hardening/checklists/requirements.md +37 -0
- package/specs/004-dev-resume-hardening/contracts/cli.md +160 -0
- package/specs/004-dev-resume-hardening/data-model.md +321 -0
- package/specs/004-dev-resume-hardening/plan.md +107 -0
- package/specs/004-dev-resume-hardening/quickstart.md +115 -0
- package/specs/004-dev-resume-hardening/research.md +142 -0
- package/specs/004-dev-resume-hardening/spec.md +221 -0
- package/specs/004-dev-resume-hardening/tasks.md +333 -0
- package/specs/005-ai-search-deploy/checklists/requirements.md +39 -0
- package/specs/005-ai-search-deploy/contracts/web-search-tool.md +241 -0
- package/specs/005-ai-search-deploy/data-model.md +130 -0
- package/specs/005-ai-search-deploy/plan.md +93 -0
- package/specs/005-ai-search-deploy/quickstart.md +96 -0
- package/specs/005-ai-search-deploy/research.md +187 -0
- package/specs/005-ai-search-deploy/spec.md +143 -0
- package/specs/005-ai-search-deploy/tasks.md +284 -0
- package/specs/006-workshop-extraction-fixes/checklists/requirements.md +61 -0
- package/specs/006-workshop-extraction-fixes/contracts/summarization-and-export.md +131 -0
- package/specs/006-workshop-extraction-fixes/data-model.md +149 -0
- package/specs/006-workshop-extraction-fixes/plan.md +123 -0
- package/specs/006-workshop-extraction-fixes/quickstart.md +101 -0
- package/specs/006-workshop-extraction-fixes/research.md +143 -0
- package/specs/006-workshop-extraction-fixes/spec.md +210 -0
- package/specs/006-workshop-extraction-fixes/tasks.md +316 -0
- package/src/cli/developCommand.ts +308 -0
- package/src/cli/directCommands.ts +195 -0
- package/src/cli/envLoader.ts +17 -0
- package/src/cli/exportCommand.ts +65 -0
- package/src/cli/index.ts +249 -0
- package/src/cli/ioContext.ts +139 -0
- package/src/cli/preflight.ts +86 -0
- package/src/cli/statusCommand.ts +118 -0
- package/src/cli/workshopCommand.ts +496 -0
- package/src/develop/checkpointState.ts +121 -0
- package/src/develop/codeGenerator.ts +402 -0
- package/src/develop/dynamicScaffolder.ts +284 -0
- package/src/develop/githubMcpAdapter.ts +199 -0
- package/src/develop/index.ts +34 -0
- package/src/develop/mcpContextEnricher.ts +279 -0
- package/src/develop/pocScaffolder.ts +646 -0
- package/src/develop/ralphLoop.ts +1044 -0
- package/src/develop/templateRegistry.ts +427 -0
- package/src/develop/testRunner.ts +276 -0
- package/src/logging/logger.ts +73 -0
- package/src/loop/conversationLoop.ts +355 -0
- package/src/loop/phaseSummarizer.ts +114 -0
- package/src/mcp/mcpManager.ts +365 -0
- package/src/mcp/mcpTransport.ts +562 -0
- package/src/mcp/retryPolicy.ts +87 -0
- package/src/mcp/webSearch.ts +388 -0
- package/src/originalPrompts/design_thinking.md +178 -0
- package/src/originalPrompts/design_thinking_persona.md +76 -0
- package/src/originalPrompts/document_generator_example.md +77 -0
- package/src/originalPrompts/document_generator_persona.md +47 -0
- package/src/originalPrompts/facilitator_persona.md +125 -0
- package/src/originalPrompts/guardrails.md +47 -0
- package/src/phases/contextSummarizer.ts +154 -0
- package/src/phases/discoveryEnricher.ts +223 -0
- package/src/phases/phaseExtractors.ts +247 -0
- package/src/phases/phaseHandlers.ts +450 -0
- package/src/prompts/design.md +51 -0
- package/src/prompts/develop-boundary.md +51 -0
- package/src/prompts/develop.md +111 -0
- package/src/prompts/discover.md +58 -0
- package/src/prompts/ideate.md +56 -0
- package/src/prompts/plan.md +51 -0
- package/src/prompts/promptLoader.ts +198 -0
- package/src/prompts/select.md +47 -0
- package/src/prompts/summarize/README.md +8 -0
- package/src/prompts/summarize/design-summary.md +37 -0
- package/src/prompts/summarize/develop-summary.md +25 -0
- package/src/prompts/summarize/ideate-summary.md +27 -0
- package/src/prompts/summarize/plan-summary.md +27 -0
- package/src/prompts/summarize/select-summary.md +21 -0
- package/src/prompts/system.md +28 -0
- package/src/sessions/exportPaths.ts +28 -0
- package/src/sessions/exportWriter.ts +490 -0
- package/src/sessions/sessionManager.ts +119 -0
- package/src/sessions/sessionStore.ts +69 -0
- package/src/shared/activitySpinner.ts +108 -0
- package/src/shared/copilotClient.ts +291 -0
- package/src/shared/data/cards.json +1249 -0
- package/src/shared/data/cardsLoader.ts +70 -0
- package/src/shared/errorClassifier.ts +160 -0
- package/src/shared/events.ts +103 -0
- package/src/shared/markdownRenderer.ts +44 -0
- package/src/shared/schemas/session.ts +346 -0
- package/src/shared/tableRenderer.ts +28 -0
- package/src/types/marked-terminal.d.ts +5 -0
- package/src/vendor/chalk.ts +2 -0
- package/src/vendor/cli-table3.ts +3 -0
- package/src/vendor/commander.ts +2 -0
- package/src/vendor/marked-terminal.ts +3 -0
- package/src/vendor/marked.ts +2 -0
- package/src/vendor/ora.ts +2 -0
- package/src/vendor/pino.ts +3 -0
- package/src/vendor/zod.ts +3 -0
- package/tests/e2e/developE2e.spec.ts +152 -0
- package/tests/e2e/developFailureE2e.spec.ts +289 -0
- package/tests/e2e/developPty.spec.ts +86 -0
- package/tests/e2e/discoveryWebSearchRelevance.spec.ts +103 -0
- package/tests/e2e/harness.spec.ts +104 -0
- package/tests/e2e/mcpLive.spec.ts +149 -0
- package/tests/e2e/newSession.e2e.spec.ts +245 -0
- package/tests/e2e/ralphLoopEnrichmentComparison.spec.ts +70 -0
- package/tests/e2e/workiqEnrichment.spec.ts +72 -0
- package/tests/e2e/zava-assessment/agent-interaction-script.md +258 -0
- package/tests/e2e/zava-assessment/company-profile.md +98 -0
- package/tests/e2e/zava-assessment/expected-results-checklist.md +454 -0
- package/tests/e2e/zavaSimulation.spec.ts +511 -0
- package/tests/fixtures/completedSession.json +141 -0
- package/tests/fixtures/test-fixture-project/package-lock.json +1585 -0
- package/tests/fixtures/test-fixture-project/package.json +12 -0
- package/tests/fixtures/test-fixture-project/src/add.ts +3 -0
- package/tests/fixtures/test-fixture-project/tests/failing.test.ts +7 -0
- package/tests/fixtures/test-fixture-project/tests/hanging.test.ts +9 -0
- package/tests/fixtures/test-fixture-project/tests/passing.test.ts +13 -0
- package/tests/fixtures/test-fixture-project/vitest.config.ts +7 -0
- package/tests/integration/autoStartConversation.spec.ts +168 -0
- package/tests/integration/defaultCommand.spec.ts +179 -0
- package/tests/integration/directCommandNonTty.spec.ts +260 -0
- package/tests/integration/directCommandTty.spec.ts +185 -0
- package/tests/integration/discoveryEnrichmentFlow.spec.ts +209 -0
- package/tests/integration/exportArtifacts.spec.ts +232 -0
- package/tests/integration/exportFallbackFlow.spec.ts +115 -0
- package/tests/integration/mcpDegradationFlow.spec.ts +231 -0
- package/tests/integration/mcpTransportFlow.spec.ts +178 -0
- package/tests/integration/newSessionFlow.spec.ts +406 -0
- package/tests/integration/pocGithubMcp.spec.ts +224 -0
- package/tests/integration/pocLocalFallback.spec.ts +205 -0
- package/tests/integration/pocScaffold.spec.ts +220 -0
- package/tests/integration/ralphLoopFlow.spec.ts +430 -0
- package/tests/integration/ralphLoopPartial.spec.ts +416 -0
- package/tests/integration/resumeAndBacktrack.spec.ts +278 -0
- package/tests/integration/spinnerLifecycle.spec.ts +270 -0
- package/tests/integration/summarizationFlow.spec.ts +135 -0
- package/tests/integration/testRunnerReal.spec.ts +63 -0
- package/tests/integration/webSearchAgent.spec.ts +155 -0
- package/tests/live/copilotSdkLive.spec.ts +149 -0
- package/tests/live/zavaFullWorkshop.spec.ts +515 -0
- package/tests/setup/loadEnv.ts +5 -0
- package/tests/unit/cli/developCommand.spec.ts +679 -0
- package/tests/unit/cli/directCommands.spec.ts +325 -0
- package/tests/unit/cli/envLoader.spec.ts +73 -0
- package/tests/unit/cli/ioContext.spec.ts +148 -0
- package/tests/unit/cli/preflight.spec.ts +125 -0
- package/tests/unit/cli/statusCommand.spec.ts +134 -0
- package/tests/unit/cli/workshopClientFallback.spec.ts +100 -0
- package/tests/unit/cli/workshopCommand.spec.ts +378 -0
- package/tests/unit/config/vitestEnvSetup.spec.ts +24 -0
- package/tests/unit/develop/checkpointState.spec.ts +378 -0
- package/tests/unit/develop/codeGenerator.spec.ts +447 -0
- package/tests/unit/develop/githubMcpAdapter.spec.ts +283 -0
- package/tests/unit/develop/mcpContextEnricher.spec.ts +564 -0
- package/tests/unit/develop/outputValidator.spec.ts +134 -0
- package/tests/unit/develop/pocScaffolder.spec.ts +451 -0
- package/tests/unit/develop/ralphLoop.spec.ts +1439 -0
- package/tests/unit/develop/templateRegistry.spec.ts +106 -0
- package/tests/unit/develop/testRunner.spec.ts +294 -0
- package/tests/unit/infraBicep.spec.ts +116 -0
- package/tests/unit/infraDeploy.spec.ts +102 -0
- package/tests/unit/infraTeardown.spec.ts +77 -0
- package/tests/unit/logging/logger.spec.ts +50 -0
- package/tests/unit/loop/conversationLoop.spec.ts +719 -0
- package/tests/unit/loop/phaseSummarizer.spec.ts +169 -0
- package/tests/unit/loop/streamingMarkdown.spec.ts +180 -0
- package/tests/unit/mcp/mcpManager.spec.ts +336 -0
- package/tests/unit/mcp/mcpTransport.spec.ts +689 -0
- package/tests/unit/mcp/retryPolicy.spec.ts +278 -0
- package/tests/unit/mcp/timeoutValidation.spec.ts +55 -0
- package/tests/unit/mcp/webSearch.spec.ts +718 -0
- package/tests/unit/phases/contextSummarizer.spec.ts +158 -0
- package/tests/unit/phases/discoveryEnricher.repeatCalls.spec.ts +125 -0
- package/tests/unit/phases/discoveryEnricher.spec.ts +512 -0
- package/tests/unit/phases/phaseExtractors.spec.ts +406 -0
- package/tests/unit/phases/phaseHandlers.spec.ts +483 -0
- package/tests/unit/prompts/promptLoader.spec.ts +144 -0
- package/tests/unit/schemas/pocSchemas.spec.ts +457 -0
- package/tests/unit/schemas/session.spec.ts +328 -0
- package/tests/unit/sessions/exportPaths.spec.ts +38 -0
- package/tests/unit/sessions/exportWriter.spec.ts +737 -0
- package/tests/unit/sessions/sessionManager.spec.ts +174 -0
- package/tests/unit/sessions/sessionStore.spec.ts +136 -0
- package/tests/unit/shared/activitySpinner.spec.ts +211 -0
- package/tests/unit/shared/cardsLoader.spec.ts +89 -0
- package/tests/unit/shared/copilotClient.spec.ts +185 -0
- package/tests/unit/shared/errorClassifier.spec.ts +152 -0
- package/tests/unit/shared/events.spec.ts +71 -0
- package/tests/unit/shared/markdownRenderer.spec.ts +42 -0
- package/tests/unit/shared/markdownRendererChunks.spec.ts +83 -0
- package/tests/unit/shared/tableRenderer.spec.ts +38 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +15 -0
- package/vitest.live.config.ts +19 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T024: Integration test for partial/failed outcomes.
|
|
3
|
+
*
|
|
4
|
+
* Tests:
|
|
5
|
+
* - max-iterations with some tests passing (partial status)
|
|
6
|
+
* - max-iterations with no tests passing (failed status)
|
|
7
|
+
* - LLM error mid-loop (error outcome on iteration, loop continues)
|
|
8
|
+
*/
|
|
9
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
10
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
|
+
import { RalphLoop } from '../../src/develop/ralphLoop.js';
|
|
15
|
+
// Mock npm install
|
|
16
|
+
vi.mock('node:child_process', async (importOriginal) => {
|
|
17
|
+
const actual = await importOriginal();
|
|
18
|
+
return {
|
|
19
|
+
...actual,
|
|
20
|
+
spawn: vi.fn((cmd, args) => {
|
|
21
|
+
if (cmd === 'npm' && args.includes('install')) {
|
|
22
|
+
return {
|
|
23
|
+
stdout: { on: vi.fn() },
|
|
24
|
+
stderr: { on: vi.fn() },
|
|
25
|
+
on: vi.fn((event, cb) => {
|
|
26
|
+
if (event === 'close')
|
|
27
|
+
cb(0);
|
|
28
|
+
}),
|
|
29
|
+
kill: vi.fn(),
|
|
30
|
+
killed: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return actual.spawn(cmd, args);
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
const require = createRequire(import.meta.url);
|
|
38
|
+
const fixtureSession = require('../fixtures/completedSession.json');
|
|
39
|
+
function makeIo() {
|
|
40
|
+
return {
|
|
41
|
+
write: vi.fn(),
|
|
42
|
+
writeActivity: vi.fn(),
|
|
43
|
+
writeToolSummary: vi.fn(),
|
|
44
|
+
readInput: vi.fn().mockResolvedValue(null),
|
|
45
|
+
showDecisionGate: vi.fn(),
|
|
46
|
+
isJsonMode: false,
|
|
47
|
+
isTTY: false,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function makeFakeScaffolder(outputDir) {
|
|
51
|
+
return {
|
|
52
|
+
scaffold: vi.fn().mockImplementation(async () => {
|
|
53
|
+
const { writeFile, mkdir } = await import('node:fs/promises');
|
|
54
|
+
await mkdir(join(outputDir, 'src'), { recursive: true });
|
|
55
|
+
await writeFile(join(outputDir, 'package.json'), JSON.stringify({
|
|
56
|
+
name: 'test-poc',
|
|
57
|
+
scripts: { test: 'vitest run' },
|
|
58
|
+
dependencies: {},
|
|
59
|
+
devDependencies: {},
|
|
60
|
+
}), 'utf-8');
|
|
61
|
+
await writeFile(join(outputDir, 'src', 'index.ts'), 'export function main() {}', 'utf-8');
|
|
62
|
+
return {
|
|
63
|
+
createdFiles: ['package.json', 'src/index.ts'],
|
|
64
|
+
skippedFiles: [],
|
|
65
|
+
context: {
|
|
66
|
+
projectName: 'test-poc',
|
|
67
|
+
ideaTitle: 'Test',
|
|
68
|
+
ideaDescription: 'Test',
|
|
69
|
+
techStack: { language: 'TypeScript', runtime: 'Node.js 20', testRunner: 'npm test' },
|
|
70
|
+
planSummary: 'Test',
|
|
71
|
+
sessionId: fixtureSession.sessionId,
|
|
72
|
+
outputDir,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}),
|
|
76
|
+
getTemplateFiles: () => [],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function makeClient() {
|
|
80
|
+
return {
|
|
81
|
+
createSession: vi.fn().mockResolvedValue({
|
|
82
|
+
send: vi.fn().mockReturnValue({
|
|
83
|
+
async *[Symbol.asyncIterator]() {
|
|
84
|
+
yield {
|
|
85
|
+
type: 'TextDelta',
|
|
86
|
+
text: '```typescript file=src/index.ts\nexport function main() { return 1; }\n```\n',
|
|
87
|
+
timestamp: '',
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
getHistory: () => [],
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
describe('RalphLoop integration — partial/failed outcomes', () => {
|
|
96
|
+
let tmpDir;
|
|
97
|
+
beforeEach(async () => {
|
|
98
|
+
tmpDir = await mkdtemp(join(tmpdir(), 'sofia-ralph-partial-'));
|
|
99
|
+
});
|
|
100
|
+
afterEach(async () => {
|
|
101
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
102
|
+
vi.clearAllMocks();
|
|
103
|
+
});
|
|
104
|
+
it('sets finalStatus=partial when some tests pass at max-iterations', async () => {
|
|
105
|
+
const io = makeIo();
|
|
106
|
+
const client = makeClient();
|
|
107
|
+
const scaffolder = makeFakeScaffolder(tmpDir);
|
|
108
|
+
const testRunner = {
|
|
109
|
+
run: vi.fn().mockResolvedValue({
|
|
110
|
+
passed: 1,
|
|
111
|
+
failed: 1,
|
|
112
|
+
skipped: 0,
|
|
113
|
+
total: 2,
|
|
114
|
+
durationMs: 400,
|
|
115
|
+
failures: [{ testName: 'suite > test B', message: 'fails always' }],
|
|
116
|
+
rawOutput: '',
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
const ralph = new RalphLoop({
|
|
120
|
+
client,
|
|
121
|
+
io,
|
|
122
|
+
session: fixtureSession,
|
|
123
|
+
outputDir: tmpDir,
|
|
124
|
+
maxIterations: 2,
|
|
125
|
+
testRunner,
|
|
126
|
+
scaffolder,
|
|
127
|
+
});
|
|
128
|
+
const result = await ralph.run();
|
|
129
|
+
expect(result.terminationReason).toBe('max-iterations');
|
|
130
|
+
expect(result.finalStatus).toBe('partial');
|
|
131
|
+
expect(result.session.poc?.terminationReason).toBe('max-iterations');
|
|
132
|
+
expect(result.session.poc?.finalStatus).toBe('partial');
|
|
133
|
+
});
|
|
134
|
+
it('sets finalStatus=failed when no tests pass at max-iterations', async () => {
|
|
135
|
+
const io = makeIo();
|
|
136
|
+
const client = makeClient();
|
|
137
|
+
const scaffolder = makeFakeScaffolder(tmpDir);
|
|
138
|
+
const testRunner = {
|
|
139
|
+
run: vi.fn().mockResolvedValue({
|
|
140
|
+
passed: 0,
|
|
141
|
+
failed: 2,
|
|
142
|
+
skipped: 0,
|
|
143
|
+
total: 2,
|
|
144
|
+
durationMs: 400,
|
|
145
|
+
failures: [
|
|
146
|
+
{ testName: 'test A', message: 'always fails' },
|
|
147
|
+
{ testName: 'test B', message: 'always fails too' },
|
|
148
|
+
],
|
|
149
|
+
rawOutput: '',
|
|
150
|
+
}),
|
|
151
|
+
};
|
|
152
|
+
const ralph = new RalphLoop({
|
|
153
|
+
client,
|
|
154
|
+
io,
|
|
155
|
+
session: fixtureSession,
|
|
156
|
+
outputDir: tmpDir,
|
|
157
|
+
maxIterations: 2,
|
|
158
|
+
testRunner,
|
|
159
|
+
scaffolder,
|
|
160
|
+
});
|
|
161
|
+
const result = await ralph.run();
|
|
162
|
+
expect(result.terminationReason).toBe('max-iterations');
|
|
163
|
+
expect(result.finalStatus).toBe('failed');
|
|
164
|
+
});
|
|
165
|
+
it('records error iteration when LLM returns empty response, continues loop', async () => {
|
|
166
|
+
const io = makeIo();
|
|
167
|
+
const scaffolder = makeFakeScaffolder(tmpDir);
|
|
168
|
+
let testCallCount = 0;
|
|
169
|
+
const testRunner = {
|
|
170
|
+
run: vi.fn().mockImplementation(async () => {
|
|
171
|
+
testCallCount++;
|
|
172
|
+
if (testCallCount >= 2) {
|
|
173
|
+
// After error iteration, tests pass
|
|
174
|
+
return {
|
|
175
|
+
passed: 1,
|
|
176
|
+
failed: 0,
|
|
177
|
+
skipped: 0,
|
|
178
|
+
total: 1,
|
|
179
|
+
durationMs: 300,
|
|
180
|
+
failures: [],
|
|
181
|
+
rawOutput: '',
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
passed: 0,
|
|
186
|
+
failed: 1,
|
|
187
|
+
skipped: 0,
|
|
188
|
+
total: 1,
|
|
189
|
+
durationMs: 400,
|
|
190
|
+
failures: [{ testName: 'test A', message: 'fails' }],
|
|
191
|
+
rawOutput: '',
|
|
192
|
+
};
|
|
193
|
+
}),
|
|
194
|
+
};
|
|
195
|
+
let llmCallCount = 0;
|
|
196
|
+
const client = {
|
|
197
|
+
createSession: vi.fn().mockResolvedValue({
|
|
198
|
+
send: vi.fn().mockImplementation(() => {
|
|
199
|
+
llmCallCount++;
|
|
200
|
+
if (llmCallCount === 1) {
|
|
201
|
+
// First LLM call: returns empty response (simulating error)
|
|
202
|
+
return {
|
|
203
|
+
async *[Symbol.asyncIterator]() {
|
|
204
|
+
// Empty - no TextDelta events
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
// Subsequent calls: return a fix
|
|
209
|
+
return {
|
|
210
|
+
async *[Symbol.asyncIterator]() {
|
|
211
|
+
yield {
|
|
212
|
+
type: 'TextDelta',
|
|
213
|
+
text: '```typescript file=src/index.ts\nexport function main() { return 1; }\n```\n',
|
|
214
|
+
timestamp: '',
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}),
|
|
219
|
+
getHistory: () => [],
|
|
220
|
+
}),
|
|
221
|
+
};
|
|
222
|
+
const ralph = new RalphLoop({
|
|
223
|
+
client,
|
|
224
|
+
io,
|
|
225
|
+
session: fixtureSession,
|
|
226
|
+
outputDir: tmpDir,
|
|
227
|
+
maxIterations: 5,
|
|
228
|
+
testRunner,
|
|
229
|
+
scaffolder,
|
|
230
|
+
});
|
|
231
|
+
const result = await ralph.run();
|
|
232
|
+
// Loop should continue after LLM error and eventually succeed or hit max
|
|
233
|
+
expect(['success', 'failed', 'partial', 'max-iterations']).toContain(result.finalStatus);
|
|
234
|
+
// Check that error iterations are recorded
|
|
235
|
+
const poc = result.session.poc;
|
|
236
|
+
const hasErrorIter = poc.iterations.some((i) => i.outcome === 'error');
|
|
237
|
+
// With empty LLM response, we should have an error iteration
|
|
238
|
+
expect(hasErrorIter).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
it('records terminationReason in session poc state', async () => {
|
|
241
|
+
const io = makeIo();
|
|
242
|
+
const client = makeClient();
|
|
243
|
+
const scaffolder = makeFakeScaffolder(tmpDir);
|
|
244
|
+
const testRunner = {
|
|
245
|
+
run: vi.fn().mockResolvedValue({
|
|
246
|
+
passed: 0,
|
|
247
|
+
failed: 1,
|
|
248
|
+
skipped: 0,
|
|
249
|
+
total: 1,
|
|
250
|
+
durationMs: 400,
|
|
251
|
+
failures: [{ testName: 'test', message: 'fails' }],
|
|
252
|
+
rawOutput: '',
|
|
253
|
+
}),
|
|
254
|
+
};
|
|
255
|
+
const ralph = new RalphLoop({
|
|
256
|
+
client,
|
|
257
|
+
io,
|
|
258
|
+
session: fixtureSession,
|
|
259
|
+
outputDir: tmpDir,
|
|
260
|
+
maxIterations: 2,
|
|
261
|
+
testRunner,
|
|
262
|
+
scaffolder,
|
|
263
|
+
});
|
|
264
|
+
const result = await ralph.run();
|
|
265
|
+
expect(result.session.poc?.terminationReason).toBeDefined();
|
|
266
|
+
expect(result.session.poc?.finalStatus).toBeDefined();
|
|
267
|
+
expect(result.session.poc?.iterations.length).toBeGreaterThan(0);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
// ── Resume from interrupted session (T019) ────────────────────────────────
|
|
271
|
+
describe('resume from interrupted session', () => {
|
|
272
|
+
let tmpDir;
|
|
273
|
+
beforeEach(async () => {
|
|
274
|
+
tmpDir = await mkdtemp(join(tmpdir(), 'ralph-resume-'));
|
|
275
|
+
});
|
|
276
|
+
afterEach(async () => {
|
|
277
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
278
|
+
});
|
|
279
|
+
it('resumes from session with 2 completed iterations and starts at iteration 3 (T019)', async () => {
|
|
280
|
+
const io = makeIo();
|
|
281
|
+
// Create a session with 2 prior iterations
|
|
282
|
+
const session = {
|
|
283
|
+
...fixtureSession,
|
|
284
|
+
poc: {
|
|
285
|
+
repoSource: 'local',
|
|
286
|
+
repoPath: tmpDir,
|
|
287
|
+
iterations: [
|
|
288
|
+
{
|
|
289
|
+
iteration: 1,
|
|
290
|
+
startedAt: new Date().toISOString(),
|
|
291
|
+
endedAt: new Date().toISOString(),
|
|
292
|
+
outcome: 'scaffold',
|
|
293
|
+
filesChanged: ['package.json', 'src/index.ts'],
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
iteration: 2,
|
|
297
|
+
startedAt: new Date().toISOString(),
|
|
298
|
+
endedAt: new Date().toISOString(),
|
|
299
|
+
outcome: 'tests-failing',
|
|
300
|
+
filesChanged: ['src/index.ts'],
|
|
301
|
+
testResults: {
|
|
302
|
+
passed: 1,
|
|
303
|
+
failed: 1,
|
|
304
|
+
skipped: 0,
|
|
305
|
+
total: 2,
|
|
306
|
+
durationMs: 200,
|
|
307
|
+
failures: [{ testName: 'test1', message: 'Expected x' }],
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
// Mock a client that returns passing code on first call
|
|
314
|
+
const passingClient = {
|
|
315
|
+
createSession: vi.fn().mockResolvedValue({
|
|
316
|
+
send: vi.fn().mockReturnValue({
|
|
317
|
+
async *[Symbol.asyncIterator]() {
|
|
318
|
+
yield {
|
|
319
|
+
type: 'TextDelta',
|
|
320
|
+
text: '```typescript file=src/index.ts\nexport function main() { return "ok"; }\n```',
|
|
321
|
+
timestamp: '',
|
|
322
|
+
};
|
|
323
|
+
},
|
|
324
|
+
}),
|
|
325
|
+
getHistory: () => [],
|
|
326
|
+
}),
|
|
327
|
+
};
|
|
328
|
+
// TestRunner that passes on first call
|
|
329
|
+
const testRunner = {
|
|
330
|
+
run: vi.fn().mockResolvedValue({
|
|
331
|
+
passed: 2,
|
|
332
|
+
failed: 0,
|
|
333
|
+
skipped: 0,
|
|
334
|
+
total: 2,
|
|
335
|
+
durationMs: 100,
|
|
336
|
+
failures: [],
|
|
337
|
+
}),
|
|
338
|
+
};
|
|
339
|
+
const scaffolder = makeFakeScaffolder(tmpDir);
|
|
340
|
+
const ralph = new RalphLoop({
|
|
341
|
+
client: passingClient,
|
|
342
|
+
io,
|
|
343
|
+
session,
|
|
344
|
+
outputDir: tmpDir,
|
|
345
|
+
maxIterations: 10,
|
|
346
|
+
testRunner,
|
|
347
|
+
scaffolder,
|
|
348
|
+
checkpoint: {
|
|
349
|
+
hasPriorRun: true,
|
|
350
|
+
completedIterations: 2,
|
|
351
|
+
lastIterationIncomplete: false,
|
|
352
|
+
resumeFromIteration: 3,
|
|
353
|
+
canSkipScaffold: false,
|
|
354
|
+
priorFinalStatus: undefined,
|
|
355
|
+
priorIterations: session.poc.iterations,
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
const result = await ralph.run();
|
|
359
|
+
// Should have seeded from prior iterations and continued
|
|
360
|
+
// Note: finalStatus may be 'partial' since makeFakeScaffolder doesn't create all
|
|
361
|
+
// files required by validatePocOutput (README.md, tsconfig.json, etc.)
|
|
362
|
+
expect(['success', 'partial']).toContain(result.finalStatus);
|
|
363
|
+
// Total iterations should include the 2 prior + scaffold + tests-passing
|
|
364
|
+
expect(result.iterationsCompleted).toBeGreaterThanOrEqual(3);
|
|
365
|
+
// Session should have iterations from resume
|
|
366
|
+
expect(result.session.poc?.iterations.length).toBeGreaterThanOrEqual(3);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test: Resume and Backtrack flow (T036)
|
|
3
|
+
*
|
|
4
|
+
* Tests the resume, backtrack, and artifact invalidation flows:
|
|
5
|
+
* - Resume an existing session and continue from the current phase
|
|
6
|
+
* - Backtrack to an earlier phase with deterministic invalidation
|
|
7
|
+
* - Verify downstream data is cleared after backtrack
|
|
8
|
+
* - Verify handler detects cleaned state as incomplete
|
|
9
|
+
* - Re-run a phase and produce fresh results after backtrack
|
|
10
|
+
*/
|
|
11
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
12
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { tmpdir } from 'node:os';
|
|
15
|
+
import { ConversationLoop } from '../../src/loop/conversationLoop.js';
|
|
16
|
+
import { createFakeCopilotClient } from '../../src/shared/copilotClient.js';
|
|
17
|
+
import { SessionStore } from '../../src/sessions/sessionStore.js';
|
|
18
|
+
import { createPhaseHandler } from '../../src/phases/phaseHandlers.js';
|
|
19
|
+
import { backtrackSession } from '../../src/sessions/sessionManager.js';
|
|
20
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
21
|
+
function createTestSession(overrides) {
|
|
22
|
+
const now = new Date().toISOString();
|
|
23
|
+
return {
|
|
24
|
+
sessionId: 'test-resume-session',
|
|
25
|
+
schemaVersion: '1.0.0',
|
|
26
|
+
createdAt: now,
|
|
27
|
+
updatedAt: now,
|
|
28
|
+
phase: 'Discover',
|
|
29
|
+
status: 'Active',
|
|
30
|
+
participants: [],
|
|
31
|
+
artifacts: { generatedFiles: [] },
|
|
32
|
+
turns: [],
|
|
33
|
+
...overrides,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function createScriptedIO(inputs, decisionGateChoice = { choice: 'continue' }) {
|
|
37
|
+
let inputIdx = 0;
|
|
38
|
+
const output = [];
|
|
39
|
+
const activityLog = [];
|
|
40
|
+
return {
|
|
41
|
+
write(text) {
|
|
42
|
+
output.push(text);
|
|
43
|
+
},
|
|
44
|
+
writeActivity(text) {
|
|
45
|
+
activityLog.push(text);
|
|
46
|
+
},
|
|
47
|
+
writeToolSummary(_toolName, _summary) {
|
|
48
|
+
// no-op
|
|
49
|
+
},
|
|
50
|
+
async readInput(_prompt) {
|
|
51
|
+
if (inputIdx >= inputs.length)
|
|
52
|
+
return null;
|
|
53
|
+
return inputs[inputIdx++];
|
|
54
|
+
},
|
|
55
|
+
async showDecisionGate(_phase) {
|
|
56
|
+
return decisionGateChoice;
|
|
57
|
+
},
|
|
58
|
+
isJsonMode: false,
|
|
59
|
+
isTTY: false,
|
|
60
|
+
output,
|
|
61
|
+
activityLog,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// ── Tests ────────────────────────────────────────────────────────────────────
|
|
65
|
+
describe('Resume and Backtrack Flow', () => {
|
|
66
|
+
let tmpDir;
|
|
67
|
+
let store;
|
|
68
|
+
beforeEach(async () => {
|
|
69
|
+
tmpDir = await mkdtemp(join(tmpdir(), 'sofia-resume-'));
|
|
70
|
+
store = new SessionStore(tmpDir);
|
|
71
|
+
});
|
|
72
|
+
afterEach(async () => {
|
|
73
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
74
|
+
});
|
|
75
|
+
it('resumes an existing session from disk', async () => {
|
|
76
|
+
// Save a session mid-Ideate
|
|
77
|
+
const session = createTestSession({
|
|
78
|
+
phase: 'Ideate',
|
|
79
|
+
businessContext: {
|
|
80
|
+
businessDescription: 'Logistics company',
|
|
81
|
+
challenges: ['Slow deliveries'],
|
|
82
|
+
},
|
|
83
|
+
workflow: {
|
|
84
|
+
activities: [{ id: 'a1', name: 'Route Planning' }],
|
|
85
|
+
edges: [],
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
await store.save(session);
|
|
89
|
+
// Load it back (resume)
|
|
90
|
+
const loaded = await store.load(session.sessionId);
|
|
91
|
+
expect(loaded.phase).toBe('Ideate');
|
|
92
|
+
expect(loaded.businessContext.businessDescription).toBe('Logistics company');
|
|
93
|
+
});
|
|
94
|
+
it('resumes and continues Ideate phase with ConversationLoop', async () => {
|
|
95
|
+
const session = createTestSession({
|
|
96
|
+
phase: 'Ideate',
|
|
97
|
+
businessContext: {
|
|
98
|
+
businessDescription: 'Logistics company',
|
|
99
|
+
challenges: ['Slow deliveries'],
|
|
100
|
+
},
|
|
101
|
+
workflow: {
|
|
102
|
+
activities: [{ id: 'a1', name: 'Route Planning' }],
|
|
103
|
+
edges: [],
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
await store.save(session);
|
|
107
|
+
const loaded = await store.load(session.sessionId);
|
|
108
|
+
const client = createFakeCopilotClient([
|
|
109
|
+
{ role: 'assistant', content: 'Let me help you brainstorm ideas for optimizing routes.' },
|
|
110
|
+
]);
|
|
111
|
+
const io = createScriptedIO(['Can we use AI for routing?', null]);
|
|
112
|
+
const handler = createPhaseHandler('Ideate');
|
|
113
|
+
await handler._preload();
|
|
114
|
+
const loop = new ConversationLoop({
|
|
115
|
+
client,
|
|
116
|
+
io,
|
|
117
|
+
session: loaded,
|
|
118
|
+
phaseHandler: handler,
|
|
119
|
+
onEvent: () => { },
|
|
120
|
+
onSessionUpdate: async (s) => { await store.save(s); },
|
|
121
|
+
});
|
|
122
|
+
const result = await loop.run();
|
|
123
|
+
expect(result.turns.length).toBeGreaterThan(0);
|
|
124
|
+
});
|
|
125
|
+
it('backtracks from Design to Ideate and clears downstream data', async () => {
|
|
126
|
+
const session = createTestSession({
|
|
127
|
+
phase: 'Design',
|
|
128
|
+
businessContext: {
|
|
129
|
+
businessDescription: 'ACME Corp',
|
|
130
|
+
challenges: ['Cost reduction'],
|
|
131
|
+
},
|
|
132
|
+
workflow: {
|
|
133
|
+
activities: [{ id: 'a1', name: 'Procurement' }],
|
|
134
|
+
edges: [],
|
|
135
|
+
},
|
|
136
|
+
ideas: [
|
|
137
|
+
{ id: 'i1', title: 'AI Procurement', description: 'Automated purchasing', workflowStepIds: ['a1'] },
|
|
138
|
+
],
|
|
139
|
+
evaluation: {
|
|
140
|
+
method: 'feasibility-value-matrix',
|
|
141
|
+
ideas: [{ ideaId: 'i1', feasibility: 4, value: 5 }],
|
|
142
|
+
},
|
|
143
|
+
turns: [
|
|
144
|
+
{ phase: 'Discover', sequence: 1, role: 'user', content: 'hello', timestamp: new Date().toISOString() },
|
|
145
|
+
{ phase: 'Ideate', sequence: 2, role: 'user', content: 'ideas', timestamp: new Date().toISOString() },
|
|
146
|
+
{ phase: 'Design', sequence: 3, role: 'user', content: 'evaluate', timestamp: new Date().toISOString() },
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
await store.save(session);
|
|
150
|
+
const loaded = await store.load(session.sessionId);
|
|
151
|
+
const result = backtrackSession(loaded, 'Ideate');
|
|
152
|
+
expect(result.success).toBe(true);
|
|
153
|
+
expect(result.session.phase).toBe('Ideate');
|
|
154
|
+
expect(result.session.ideas).toBeUndefined();
|
|
155
|
+
expect(result.session.evaluation).toBeUndefined();
|
|
156
|
+
// Discover data preserved
|
|
157
|
+
expect(result.session.businessContext).toBeDefined();
|
|
158
|
+
// Only Discover turns remain
|
|
159
|
+
expect(result.session.turns?.length).toBe(1);
|
|
160
|
+
expect(result.session.turns[0].phase).toBe('Discover');
|
|
161
|
+
// Save backtracked session
|
|
162
|
+
await store.save(result.session);
|
|
163
|
+
const reloaded = await store.load(session.sessionId);
|
|
164
|
+
expect(reloaded.phase).toBe('Ideate');
|
|
165
|
+
});
|
|
166
|
+
it('re-runs Ideate after backtrack and produces fresh ideas', async () => {
|
|
167
|
+
const session = createTestSession({
|
|
168
|
+
phase: 'Ideate',
|
|
169
|
+
status: 'Active',
|
|
170
|
+
businessContext: {
|
|
171
|
+
businessDescription: 'ACME Corp',
|
|
172
|
+
challenges: ['Cost reduction'],
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
// LLM returns fresh ideas in JSON
|
|
176
|
+
const client = createFakeCopilotClient([
|
|
177
|
+
{
|
|
178
|
+
role: 'assistant',
|
|
179
|
+
content: '```json\n[{"id": "new-1", "title": "Smart Scheduling", "description": "AI scheduling", "workflowStepIds": ["a1"]}]\n```',
|
|
180
|
+
},
|
|
181
|
+
]);
|
|
182
|
+
const io = createScriptedIO(['Generate new ideas', null]);
|
|
183
|
+
const handler = createPhaseHandler('Ideate');
|
|
184
|
+
await handler._preload();
|
|
185
|
+
const loop = new ConversationLoop({
|
|
186
|
+
client,
|
|
187
|
+
io,
|
|
188
|
+
session,
|
|
189
|
+
phaseHandler: handler,
|
|
190
|
+
onEvent: () => { },
|
|
191
|
+
onSessionUpdate: async (s) => { await store.save(s); },
|
|
192
|
+
});
|
|
193
|
+
const result = await loop.run();
|
|
194
|
+
// The extractResult should have captured the ideas
|
|
195
|
+
expect(result.ideas).toBeDefined();
|
|
196
|
+
expect(result.ideas.length).toBeGreaterThan(0);
|
|
197
|
+
expect(result.ideas[0].id).toBe('new-1');
|
|
198
|
+
});
|
|
199
|
+
it('backtrack to Discover clears all downstream phase data', () => {
|
|
200
|
+
const session = createTestSession({
|
|
201
|
+
phase: 'Plan',
|
|
202
|
+
businessContext: {
|
|
203
|
+
businessDescription: 'Tech Co',
|
|
204
|
+
challenges: ['Scaling'],
|
|
205
|
+
},
|
|
206
|
+
workflow: {
|
|
207
|
+
activities: [{ id: 'a1', name: 'Deploy' }],
|
|
208
|
+
edges: [],
|
|
209
|
+
},
|
|
210
|
+
ideas: [
|
|
211
|
+
{ id: 'i1', title: 'Auto-scale', description: 'Auto scaling', workflowStepIds: ['a1'] },
|
|
212
|
+
],
|
|
213
|
+
evaluation: {
|
|
214
|
+
method: 'feasibility-value-matrix',
|
|
215
|
+
ideas: [{ ideaId: 'i1', feasibility: 5, value: 5 }],
|
|
216
|
+
},
|
|
217
|
+
selection: {
|
|
218
|
+
ideaId: 'i1',
|
|
219
|
+
selectionRationale: 'Only option',
|
|
220
|
+
confirmedByUser: true,
|
|
221
|
+
},
|
|
222
|
+
plan: {
|
|
223
|
+
milestones: [{ id: 'm1', title: 'Phase 1', items: ['Setup'] }],
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
const result = backtrackSession(session, 'Discover');
|
|
227
|
+
expect(result.success).toBe(true);
|
|
228
|
+
expect(result.invalidatedPhases).toContain('Discover');
|
|
229
|
+
expect(result.invalidatedPhases).toContain('Ideate');
|
|
230
|
+
expect(result.invalidatedPhases).toContain('Design');
|
|
231
|
+
expect(result.invalidatedPhases).toContain('Select');
|
|
232
|
+
expect(result.invalidatedPhases).toContain('Plan');
|
|
233
|
+
const s = result.session;
|
|
234
|
+
expect(s.businessContext).toBeUndefined();
|
|
235
|
+
expect(s.workflow).toBeUndefined();
|
|
236
|
+
expect(s.ideas).toBeUndefined();
|
|
237
|
+
expect(s.evaluation).toBeUndefined();
|
|
238
|
+
expect(s.selection).toBeUndefined();
|
|
239
|
+
expect(s.plan).toBeUndefined();
|
|
240
|
+
});
|
|
241
|
+
it('forward backtrack is rejected', () => {
|
|
242
|
+
const session = createTestSession({ phase: 'Ideate' });
|
|
243
|
+
const result = backtrackSession(session, 'Plan');
|
|
244
|
+
expect(result.success).toBe(false);
|
|
245
|
+
expect(result.error).toContain('forward');
|
|
246
|
+
});
|
|
247
|
+
});
|