@nathapp/nax 0.50.3 → 0.51.2
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/CHANGELOG.md +30 -0
- package/README.md +177 -104
- package/dist/nax.js +417 -213
- package/package.json +1 -3
- package/bin/nax.ts +0 -1195
- package/src/acceptance/fix-generator.ts +0 -322
- package/src/acceptance/generator.ts +0 -415
- package/src/acceptance/index.ts +0 -42
- package/src/acceptance/refinement.ts +0 -224
- package/src/acceptance/templates/cli.ts +0 -47
- package/src/acceptance/templates/component.ts +0 -78
- package/src/acceptance/templates/e2e.ts +0 -43
- package/src/acceptance/templates/index.ts +0 -21
- package/src/acceptance/templates/snapshot.ts +0 -50
- package/src/acceptance/templates/unit.ts +0 -48
- package/src/acceptance/types.ts +0 -138
- package/src/agents/acp/adapter.ts +0 -888
- package/src/agents/acp/cost.ts +0 -9
- package/src/agents/acp/index.ts +0 -7
- package/src/agents/acp/interaction-bridge.ts +0 -126
- package/src/agents/acp/parser.ts +0 -119
- package/src/agents/acp/spawn-client.ts +0 -373
- package/src/agents/acp/types.ts +0 -22
- package/src/agents/aider/adapter.ts +0 -135
- package/src/agents/claude/adapter.ts +0 -258
- package/src/agents/claude/complete.ts +0 -80
- package/src/agents/claude/cost.ts +0 -16
- package/src/agents/claude/execution.ts +0 -215
- package/src/agents/claude/index.ts +0 -3
- package/src/agents/claude/interactive.ts +0 -77
- package/src/agents/claude/plan.ts +0 -179
- package/src/agents/codex/adapter.ts +0 -153
- package/src/agents/cost/calculate.ts +0 -154
- package/src/agents/cost/index.ts +0 -10
- package/src/agents/cost/parse.ts +0 -97
- package/src/agents/cost/pricing.ts +0 -59
- package/src/agents/cost/types.ts +0 -45
- package/src/agents/gemini/adapter.ts +0 -177
- package/src/agents/index.ts +0 -18
- package/src/agents/opencode/adapter.ts +0 -106
- package/src/agents/registry.ts +0 -136
- package/src/agents/shared/decompose.ts +0 -154
- package/src/agents/shared/model-resolution.ts +0 -43
- package/src/agents/shared/types-extended.ts +0 -164
- package/src/agents/shared/validation.ts +0 -69
- package/src/agents/shared/version-detection.ts +0 -109
- package/src/agents/types.ts +0 -205
- package/src/analyze/classifier.ts +0 -282
- package/src/analyze/index.ts +0 -16
- package/src/analyze/scanner.ts +0 -171
- package/src/analyze/types.ts +0 -51
- package/src/cli/accept.ts +0 -108
- package/src/cli/agents.ts +0 -87
- package/src/cli/analyze-parser.ts +0 -291
- package/src/cli/analyze.ts +0 -352
- package/src/cli/config-descriptions.ts +0 -219
- package/src/cli/config-diff.ts +0 -103
- package/src/cli/config-display.ts +0 -285
- package/src/cli/config-get.ts +0 -55
- package/src/cli/config.ts +0 -14
- package/src/cli/constitution.ts +0 -17
- package/src/cli/diagnose-analysis.ts +0 -159
- package/src/cli/diagnose-formatter.ts +0 -87
- package/src/cli/diagnose.ts +0 -203
- package/src/cli/generate.ts +0 -250
- package/src/cli/index.ts +0 -42
- package/src/cli/init-context.ts +0 -405
- package/src/cli/init-detect.ts +0 -303
- package/src/cli/init.ts +0 -296
- package/src/cli/interact.ts +0 -295
- package/src/cli/plan.ts +0 -509
- package/src/cli/plugins.ts +0 -122
- package/src/cli/prompts-export.ts +0 -58
- package/src/cli/prompts-init.ts +0 -200
- package/src/cli/prompts-main.ts +0 -183
- package/src/cli/prompts-shared.ts +0 -70
- package/src/cli/prompts-tdd.ts +0 -88
- package/src/cli/prompts.ts +0 -17
- package/src/cli/runs.ts +0 -174
- package/src/cli/status-cost.ts +0 -151
- package/src/cli/status-features.ts +0 -405
- package/src/cli/status.ts +0 -13
- package/src/commands/common.ts +0 -171
- package/src/commands/diagnose.ts +0 -17
- package/src/commands/index.ts +0 -9
- package/src/commands/logs-formatter.ts +0 -201
- package/src/commands/logs-reader.ts +0 -171
- package/src/commands/logs.ts +0 -103
- package/src/commands/precheck.ts +0 -86
- package/src/commands/runs.ts +0 -220
- package/src/commands/unlock.ts +0 -96
- package/src/config/defaults.ts +0 -218
- package/src/config/index.ts +0 -22
- package/src/config/loader.ts +0 -143
- package/src/config/merge.ts +0 -106
- package/src/config/merger.ts +0 -147
- package/src/config/path-security.ts +0 -121
- package/src/config/paths.ts +0 -27
- package/src/config/permissions.ts +0 -63
- package/src/config/runtime-types.ts +0 -522
- package/src/config/schema-types.ts +0 -53
- package/src/config/schema.ts +0 -60
- package/src/config/schemas.ts +0 -426
- package/src/config/test-strategy.ts +0 -71
- package/src/config/types.ts +0 -57
- package/src/config/validate.ts +0 -103
- package/src/constitution/generator.ts +0 -158
- package/src/constitution/generators/aider.ts +0 -41
- package/src/constitution/generators/claude.ts +0 -35
- package/src/constitution/generators/cursor.ts +0 -36
- package/src/constitution/generators/opencode.ts +0 -38
- package/src/constitution/generators/types.ts +0 -33
- package/src/constitution/generators/windsurf.ts +0 -36
- package/src/constitution/index.ts +0 -11
- package/src/constitution/loader.ts +0 -121
- package/src/constitution/types.ts +0 -31
- package/src/context/auto-detect.ts +0 -228
- package/src/context/builder.ts +0 -299
- package/src/context/elements.ts +0 -122
- package/src/context/formatter.ts +0 -107
- package/src/context/generator.ts +0 -343
- package/src/context/generators/aider.ts +0 -34
- package/src/context/generators/claude.ts +0 -28
- package/src/context/generators/codex.ts +0 -28
- package/src/context/generators/cursor.ts +0 -28
- package/src/context/generators/gemini.ts +0 -28
- package/src/context/generators/opencode.ts +0 -30
- package/src/context/generators/windsurf.ts +0 -28
- package/src/context/greenfield.ts +0 -114
- package/src/context/index.ts +0 -34
- package/src/context/injector.ts +0 -279
- package/src/context/parent-context.ts +0 -39
- package/src/context/test-scanner.ts +0 -370
- package/src/context/types.ts +0 -98
- package/src/decompose/apply.ts +0 -50
- package/src/decompose/builder.ts +0 -181
- package/src/decompose/index.ts +0 -8
- package/src/decompose/sections/codebase.ts +0 -26
- package/src/decompose/sections/constraints.ts +0 -32
- package/src/decompose/sections/index.ts +0 -4
- package/src/decompose/sections/sibling-stories.ts +0 -25
- package/src/decompose/sections/target-story.ts +0 -31
- package/src/decompose/types.ts +0 -55
- package/src/decompose/validators/complexity.ts +0 -45
- package/src/decompose/validators/coverage.ts +0 -134
- package/src/decompose/validators/dependency.ts +0 -91
- package/src/decompose/validators/index.ts +0 -35
- package/src/decompose/validators/overlap.ts +0 -128
- package/src/errors.ts +0 -67
- package/src/execution/batching.ts +0 -157
- package/src/execution/crash-heartbeat.ts +0 -77
- package/src/execution/crash-recovery.ts +0 -79
- package/src/execution/crash-signals.ts +0 -165
- package/src/execution/crash-writer.ts +0 -154
- package/src/execution/deferred-review.ts +0 -105
- package/src/execution/dry-run.ts +0 -81
- package/src/execution/escalation/escalation.ts +0 -46
- package/src/execution/escalation/index.ts +0 -13
- package/src/execution/escalation/tier-escalation.ts +0 -346
- package/src/execution/escalation/tier-outcome.ts +0 -143
- package/src/execution/executor-types.ts +0 -73
- package/src/execution/helpers.ts +0 -38
- package/src/execution/index.ts +0 -27
- package/src/execution/iteration-runner.ts +0 -160
- package/src/execution/lifecycle/acceptance-loop.ts +0 -309
- package/src/execution/lifecycle/headless-formatter.ts +0 -83
- package/src/execution/lifecycle/index.ts +0 -11
- package/src/execution/lifecycle/parallel-lifecycle.ts +0 -101
- package/src/execution/lifecycle/precheck-runner.ts +0 -140
- package/src/execution/lifecycle/run-cleanup.ts +0 -81
- package/src/execution/lifecycle/run-completion.ts +0 -247
- package/src/execution/lifecycle/run-initialization.ts +0 -187
- package/src/execution/lifecycle/run-regression.ts +0 -305
- package/src/execution/lifecycle/run-setup.ts +0 -240
- package/src/execution/lifecycle/story-size-prompts.ts +0 -123
- package/src/execution/lock.ts +0 -129
- package/src/execution/parallel-coordinator.ts +0 -281
- package/src/execution/parallel-executor-rectification-pass.ts +0 -117
- package/src/execution/parallel-executor-rectify.ts +0 -136
- package/src/execution/parallel-executor.ts +0 -330
- package/src/execution/parallel-worker.ts +0 -149
- package/src/execution/parallel.ts +0 -13
- package/src/execution/pid-registry.ts +0 -275
- package/src/execution/pipeline-result-handler.ts +0 -221
- package/src/execution/progress.ts +0 -27
- package/src/execution/queue-handler.ts +0 -109
- package/src/execution/runner-completion.ts +0 -171
- package/src/execution/runner-execution.ts +0 -243
- package/src/execution/runner-setup.ts +0 -86
- package/src/execution/runner.ts +0 -265
- package/src/execution/sequential-executor.ts +0 -219
- package/src/execution/status-file.ts +0 -264
- package/src/execution/status-writer.ts +0 -181
- package/src/execution/story-context.ts +0 -266
- package/src/execution/story-selector.ts +0 -76
- package/src/execution/test-output-parser.ts +0 -14
- package/src/execution/timeout-handler.ts +0 -100
- package/src/hooks/index.ts +0 -2
- package/src/hooks/runner.ts +0 -280
- package/src/hooks/types.ts +0 -79
- package/src/interaction/chain.ts +0 -170
- package/src/interaction/index.ts +0 -61
- package/src/interaction/init.ts +0 -84
- package/src/interaction/plugins/auto.ts +0 -243
- package/src/interaction/plugins/cli.ts +0 -300
- package/src/interaction/plugins/telegram.ts +0 -384
- package/src/interaction/plugins/webhook.ts +0 -286
- package/src/interaction/state.ts +0 -171
- package/src/interaction/triggers.ts +0 -250
- package/src/interaction/types.ts +0 -170
- package/src/logger/formatters.ts +0 -84
- package/src/logger/index.ts +0 -16
- package/src/logger/logger.ts +0 -296
- package/src/logger/types.ts +0 -48
- package/src/logging/formatter.ts +0 -355
- package/src/logging/index.ts +0 -22
- package/src/logging/types.ts +0 -93
- package/src/metrics/aggregator.ts +0 -191
- package/src/metrics/index.ts +0 -14
- package/src/metrics/tracker.ts +0 -200
- package/src/metrics/types.ts +0 -115
- package/src/optimizer/index.ts +0 -63
- package/src/optimizer/noop.optimizer.ts +0 -24
- package/src/optimizer/rule-based.optimizer.ts +0 -248
- package/src/optimizer/types.ts +0 -53
- package/src/pipeline/event-bus.ts +0 -297
- package/src/pipeline/events.ts +0 -130
- package/src/pipeline/index.ts +0 -19
- package/src/pipeline/runner.ts +0 -149
- package/src/pipeline/stages/acceptance-setup.ts +0 -144
- package/src/pipeline/stages/acceptance.ts +0 -215
- package/src/pipeline/stages/autofix.ts +0 -262
- package/src/pipeline/stages/completion.ts +0 -110
- package/src/pipeline/stages/constitution.ts +0 -63
- package/src/pipeline/stages/context.ts +0 -122
- package/src/pipeline/stages/execution.ts +0 -359
- package/src/pipeline/stages/index.ts +0 -86
- package/src/pipeline/stages/optimizer.ts +0 -74
- package/src/pipeline/stages/prompt.ts +0 -79
- package/src/pipeline/stages/queue-check.ts +0 -103
- package/src/pipeline/stages/rectify.ts +0 -101
- package/src/pipeline/stages/regression.ts +0 -99
- package/src/pipeline/stages/review.ts +0 -94
- package/src/pipeline/stages/routing.ts +0 -276
- package/src/pipeline/stages/verify.ts +0 -286
- package/src/pipeline/subscribers/events-writer.ts +0 -135
- package/src/pipeline/subscribers/hooks.ts +0 -179
- package/src/pipeline/subscribers/interaction.ts +0 -103
- package/src/pipeline/subscribers/registry.ts +0 -73
- package/src/pipeline/subscribers/reporters.ts +0 -174
- package/src/pipeline/types.ts +0 -220
- package/src/plugins/extensions.ts +0 -225
- package/src/plugins/index.ts +0 -33
- package/src/plugins/loader.ts +0 -352
- package/src/plugins/plugin-logger.ts +0 -41
- package/src/plugins/registry.ts +0 -168
- package/src/plugins/types.ts +0 -206
- package/src/plugins/validator.ts +0 -352
- package/src/prd/index.ts +0 -220
- package/src/prd/schema.ts +0 -268
- package/src/prd/types.ts +0 -273
- package/src/prd/validate.ts +0 -41
- package/src/precheck/checks-agents.ts +0 -63
- package/src/precheck/checks-blockers.ts +0 -23
- package/src/precheck/checks-cli.ts +0 -68
- package/src/precheck/checks-config.ts +0 -102
- package/src/precheck/checks-git.ts +0 -117
- package/src/precheck/checks-system.ts +0 -101
- package/src/precheck/checks-warnings.ts +0 -221
- package/src/precheck/checks.ts +0 -36
- package/src/precheck/index.ts +0 -374
- package/src/precheck/story-size-gate.ts +0 -144
- package/src/precheck/types.ts +0 -31
- package/src/prompts/builder.ts +0 -166
- package/src/prompts/index.ts +0 -2
- package/src/prompts/loader.ts +0 -43
- package/src/prompts/sections/conventions.ts +0 -19
- package/src/prompts/sections/hermetic.ts +0 -41
- package/src/prompts/sections/index.ts +0 -12
- package/src/prompts/sections/isolation.ts +0 -70
- package/src/prompts/sections/role-task.ts +0 -182
- package/src/prompts/sections/story.ts +0 -55
- package/src/prompts/sections/verdict.ts +0 -70
- package/src/prompts/types.ts +0 -21
- package/src/queue/index.ts +0 -2
- package/src/queue/manager.ts +0 -254
- package/src/queue/types.ts +0 -54
- package/src/review/index.ts +0 -8
- package/src/review/orchestrator.ts +0 -154
- package/src/review/runner.ts +0 -303
- package/src/review/types.ts +0 -70
- package/src/routing/batch-route.ts +0 -35
- package/src/routing/builder.ts +0 -81
- package/src/routing/chain.ts +0 -75
- package/src/routing/content-hash.ts +0 -25
- package/src/routing/index.ts +0 -20
- package/src/routing/loader.ts +0 -62
- package/src/routing/router.ts +0 -305
- package/src/routing/strategies/adaptive.ts +0 -215
- package/src/routing/strategies/index.ts +0 -8
- package/src/routing/strategies/keyword.ts +0 -180
- package/src/routing/strategies/llm-prompts.ts +0 -224
- package/src/routing/strategies/llm.ts +0 -320
- package/src/routing/strategies/manual.ts +0 -50
- package/src/routing/strategy.ts +0 -102
- package/src/tdd/cleanup.ts +0 -120
- package/src/tdd/index.ts +0 -22
- package/src/tdd/isolation.ts +0 -117
- package/src/tdd/orchestrator.ts +0 -406
- package/src/tdd/prompts.ts +0 -40
- package/src/tdd/rectification-gate.ts +0 -274
- package/src/tdd/session-runner.ts +0 -263
- package/src/tdd/types.ts +0 -84
- package/src/tdd/verdict-reader.ts +0 -266
- package/src/tdd/verdict.ts +0 -152
- package/src/tui/App.tsx +0 -265
- package/src/tui/components/AgentPanel.tsx +0 -75
- package/src/tui/components/CostOverlay.tsx +0 -118
- package/src/tui/components/HelpOverlay.tsx +0 -107
- package/src/tui/components/StatusBar.tsx +0 -63
- package/src/tui/components/StoriesPanel.tsx +0 -177
- package/src/tui/hooks/useKeyboard.ts +0 -142
- package/src/tui/hooks/useLayout.ts +0 -137
- package/src/tui/hooks/usePipelineEvents.ts +0 -183
- package/src/tui/hooks/usePty.ts +0 -189
- package/src/tui/index.tsx +0 -38
- package/src/tui/types.ts +0 -76
- package/src/utils/errors.ts +0 -12
- package/src/utils/git.ts +0 -245
- package/src/utils/json-file.ts +0 -72
- package/src/utils/log-test-output.ts +0 -25
- package/src/utils/path-security.ts +0 -73
- package/src/utils/queue-writer.ts +0 -54
- package/src/verification/crash-detector.ts +0 -34
- package/src/verification/executor.ts +0 -250
- package/src/verification/index.ts +0 -12
- package/src/verification/orchestrator-types.ts +0 -154
- package/src/verification/orchestrator.ts +0 -76
- package/src/verification/parser.ts +0 -220
- package/src/verification/rectification-loop.ts +0 -172
- package/src/verification/rectification.ts +0 -108
- package/src/verification/runners.ts +0 -129
- package/src/verification/smart-runner.ts +0 -307
- package/src/verification/strategies/acceptance.ts +0 -136
- package/src/verification/strategies/regression.ts +0 -90
- package/src/verification/strategies/scoped.ts +0 -154
- package/src/verification/types.ts +0 -117
- package/src/version.ts +0 -40
- package/src/worktree/dispatcher.ts +0 -6
- package/src/worktree/index.ts +0 -2
- package/src/worktree/manager.ts +0 -193
- package/src/worktree/merge.ts +0 -302
- package/src/worktree/types.ts +0 -4
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Smart Runner — Git diff file detection
|
|
3
|
-
*
|
|
4
|
-
* Detects changed TypeScript source files using git diff,
|
|
5
|
-
* enabling targeted test runs on only the files that changed.
|
|
6
|
-
*/
|
|
7
|
-
import { gitWithTimeout } from "../utils/git";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Bun API wrappers — defined before functions to avoid circular type inference.
|
|
11
|
-
* Use closures so tests mocking Bun.Glob / Bun.file on the global namespace
|
|
12
|
-
* continue to work (closures evaluate Bun.* at call time).
|
|
13
|
-
*
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
const _bunDeps = {
|
|
17
|
-
glob: (p: string) => new Bun.Glob(p),
|
|
18
|
-
file: (path: string) => Bun.file(path),
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Get TypeScript source files changed since the previous commit.
|
|
23
|
-
*
|
|
24
|
-
* Runs `git diff --name-only HEAD~1` in the given workdir and filters
|
|
25
|
-
* results to only `.ts` files under `src/`. Returns an empty array on
|
|
26
|
-
* any git error (not a repo, no previous commit, etc.).
|
|
27
|
-
*
|
|
28
|
-
* @param workdir - Working directory to run git command in
|
|
29
|
-
* @returns Array of changed .ts file paths relative to the repo root
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* const files = await getChangedSourceFiles("/path/to/repo");
|
|
34
|
-
* // Returns: ["src/foo/bar.ts", "src/utils/git.ts"]
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
/**
|
|
38
|
-
* Map source files to their corresponding test files.
|
|
39
|
-
*
|
|
40
|
-
* For each file in `sourceFiles`, checks both:
|
|
41
|
-
* - `<workdir>/test/unit/<relative-path>.test.ts`
|
|
42
|
-
* - `<workdir>/test/integration/<relative-path>.test.ts`
|
|
43
|
-
*
|
|
44
|
-
* where `<relative-path>` is the file path with the leading `src/` stripped
|
|
45
|
-
* and the `.ts` extension replaced with `.test.ts`.
|
|
46
|
-
*
|
|
47
|
-
* Only returns paths that actually exist on disk.
|
|
48
|
-
*
|
|
49
|
-
* @param sourceFiles - Array of source file paths (e.g. `["src/foo/bar.ts"]`)
|
|
50
|
-
* @param workdir - Absolute path to the repository root
|
|
51
|
-
* @returns Existing test file paths (absolute)
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* const tests = await mapSourceToTests(["src/foo/bar.ts"], "/repo");
|
|
56
|
-
* // Returns: ["/repo/test/unit/foo/bar.test.ts"] (if it exists)
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
/**
|
|
60
|
-
* Extract searchable identifiers from a source file path.
|
|
61
|
-
*
|
|
62
|
-
* For `src/routing/strategies/llm.ts`, returns:
|
|
63
|
-
* ["/llm", "routing/strategies/llm"]
|
|
64
|
-
*
|
|
65
|
-
* @internal
|
|
66
|
-
*/
|
|
67
|
-
function extractSearchTerms(sourceFile: string): string[] {
|
|
68
|
-
const withoutSrc = sourceFile.replace(/^src\//, "");
|
|
69
|
-
const withoutExt = withoutSrc.replace(/\.ts$/, "");
|
|
70
|
-
const parts = withoutExt.split("/");
|
|
71
|
-
const basename = parts[parts.length - 1];
|
|
72
|
-
// Use "/basename" to avoid matching short names as plain words
|
|
73
|
-
return [`/${basename}`, withoutExt];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Pass 2 — import-grep fallback.
|
|
78
|
-
*
|
|
79
|
-
* Scans test files matching `testFilePatterns` and returns those that
|
|
80
|
-
* contain an import reference to any of the given `sourceFiles`.
|
|
81
|
-
*
|
|
82
|
-
* @param sourceFiles - Changed source file paths (e.g. `["src/routing/strategies/llm.ts"]`)
|
|
83
|
-
* @param workdir - Absolute path to the repository root
|
|
84
|
-
* @param testFilePatterns - Glob patterns to scan for test files
|
|
85
|
-
* @returns Matching test file paths (absolute)
|
|
86
|
-
*/
|
|
87
|
-
export async function importGrepFallback(
|
|
88
|
-
sourceFiles: string[],
|
|
89
|
-
workdir: string,
|
|
90
|
-
testFilePatterns: string[],
|
|
91
|
-
): Promise<string[]> {
|
|
92
|
-
if (sourceFiles.length === 0 || testFilePatterns.length === 0) return [];
|
|
93
|
-
|
|
94
|
-
// Collect search terms from all changed source files
|
|
95
|
-
const searchTerms = sourceFiles.flatMap(extractSearchTerms);
|
|
96
|
-
|
|
97
|
-
// Scan all test files matching the configured patterns
|
|
98
|
-
const testFilePaths: string[] = [];
|
|
99
|
-
for (const pattern of testFilePatterns) {
|
|
100
|
-
const glob = _bunDeps.glob(pattern);
|
|
101
|
-
for await (const file of glob.scan(workdir)) {
|
|
102
|
-
testFilePaths.push(`${workdir}/${file}`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Return test files that contain any of the search terms
|
|
107
|
-
const matched: string[] = [];
|
|
108
|
-
for (const testFile of testFilePaths) {
|
|
109
|
-
let content: string;
|
|
110
|
-
try {
|
|
111
|
-
content = await _bunDeps.file(testFile).text();
|
|
112
|
-
} catch {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
for (const term of searchTerms) {
|
|
116
|
-
if (content.includes(term)) {
|
|
117
|
-
matched.push(testFile);
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return matched;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export async function mapSourceToTests(sourceFiles: string[], workdir: string): Promise<string[]> {
|
|
127
|
-
const result: string[] = [];
|
|
128
|
-
|
|
129
|
-
for (const sourceFile of sourceFiles) {
|
|
130
|
-
// Strip leading "src/" and replace ".ts" with ".test.ts"
|
|
131
|
-
const relative = sourceFile.replace(/^src\//, "").replace(/\.ts$/, ".test.ts");
|
|
132
|
-
|
|
133
|
-
const candidates = [`${workdir}/test/unit/${relative}`, `${workdir}/test/integration/${relative}`];
|
|
134
|
-
|
|
135
|
-
for (const candidate of candidates) {
|
|
136
|
-
if (await _bunDeps.file(candidate).exists()) {
|
|
137
|
-
result.push(candidate);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Build a scoped test command targeting specific test files.
|
|
147
|
-
*
|
|
148
|
-
* When `testFiles` is non-empty, replaces the last path-like argument in
|
|
149
|
-
* `baseCommand` (a token containing `/`) with the specific test file paths
|
|
150
|
-
* joined by spaces. If no path argument is found, appends the test files.
|
|
151
|
-
*
|
|
152
|
-
* When `testFiles` is empty, returns `baseCommand` unchanged (full-suite
|
|
153
|
-
* fallback).
|
|
154
|
-
*
|
|
155
|
-
* @param testFiles - Test file paths to scope the run to
|
|
156
|
-
* @param baseCommand - Full test command (e.g. `"bun test test/"`)
|
|
157
|
-
* @returns Scoped command string
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* buildSmartTestCommand(["test/unit/foo.test.ts"], "bun test test/")
|
|
162
|
-
* // => "bun test test/unit/foo.test.ts"
|
|
163
|
-
*
|
|
164
|
-
* buildSmartTestCommand([], "bun test test/")
|
|
165
|
-
* // => "bun test test/"
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
export function buildSmartTestCommand(testFiles: string[], baseCommand: string): string {
|
|
169
|
-
if (testFiles.length === 0) {
|
|
170
|
-
return baseCommand;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const parts = baseCommand.trim().split(/\s+/);
|
|
174
|
-
|
|
175
|
-
// Find the last token that looks like a path (contains '/')
|
|
176
|
-
let lastPathIndex = -1;
|
|
177
|
-
for (let i = parts.length - 1; i >= 0; i--) {
|
|
178
|
-
if (parts[i].includes("/")) {
|
|
179
|
-
lastPathIndex = i;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (lastPathIndex === -1) {
|
|
185
|
-
// No path argument — append test files
|
|
186
|
-
return `${baseCommand} ${testFiles.join(" ")}`;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Replace the last path argument with the specific test files,
|
|
190
|
-
// preserving any flags that appear after the path (e.g. --timeout=60000).
|
|
191
|
-
const beforePath = parts.slice(0, lastPathIndex);
|
|
192
|
-
const afterPath = parts.slice(lastPathIndex + 1);
|
|
193
|
-
const newParts = [...beforePath, ...testFiles, ...afterPath];
|
|
194
|
-
return newParts.join(" ");
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Get TypeScript source files changed since the previous commit.
|
|
199
|
-
*
|
|
200
|
-
* Runs `git diff --name-only <ref>` in the given workdir and filters
|
|
201
|
-
* results to only `.ts` files under the relevant source prefix.
|
|
202
|
-
*
|
|
203
|
-
* In a monorepo, git returns paths relative to the git root (e.g.
|
|
204
|
-
* `packages/api/src/foo.ts`). When `packagePrefix` is set to the
|
|
205
|
-
* story's workdir (e.g. `"packages/api"`), the filter is scoped to
|
|
206
|
-
* `<packagePrefix>/src/` instead of just `src/`.
|
|
207
|
-
*
|
|
208
|
-
* @param workdir - Working directory to run git command in
|
|
209
|
-
* @param baseRef - Git ref for diff base (default: HEAD~1)
|
|
210
|
-
* @param packagePrefix - Story workdir relative to repo root (e.g. "packages/api")
|
|
211
|
-
* @returns Array of changed .ts file paths relative to the git root
|
|
212
|
-
*/
|
|
213
|
-
export async function getChangedSourceFiles(
|
|
214
|
-
workdir: string,
|
|
215
|
-
baseRef?: string,
|
|
216
|
-
packagePrefix?: string,
|
|
217
|
-
): Promise<string[]> {
|
|
218
|
-
try {
|
|
219
|
-
// FEAT-010: Use per-attempt baseRef for precise diff; fall back to HEAD~1 if not provided
|
|
220
|
-
const ref = baseRef ?? "HEAD~1";
|
|
221
|
-
// BUG-039: Use gitWithTimeout to prevent orphan processes on hang
|
|
222
|
-
const { stdout, exitCode } = await gitWithTimeout(["diff", "--name-only", ref], workdir);
|
|
223
|
-
if (exitCode !== 0) return [];
|
|
224
|
-
|
|
225
|
-
const lines = stdout.trim().split("\n").filter(Boolean);
|
|
226
|
-
|
|
227
|
-
// MW-006: scope filter to package prefix in monorepo
|
|
228
|
-
const srcPrefix = packagePrefix ? `${packagePrefix}/src/` : "src/";
|
|
229
|
-
return lines.filter((f) => f.startsWith(srcPrefix) && f.endsWith(".ts"));
|
|
230
|
-
} catch {
|
|
231
|
-
return [];
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Map test files back to their corresponding source files.
|
|
237
|
-
*
|
|
238
|
-
* For each test file path, converts it back to the likely source file path.
|
|
239
|
-
* Handles both `test/unit/` and `test/integration/` conventions.
|
|
240
|
-
* Only processes .test.ts files (not .test.js).
|
|
241
|
-
*
|
|
242
|
-
* @param testFiles - Array of test file paths (e.g. `["/repo/test/unit/foo/bar.test.ts"]`)
|
|
243
|
-
* @param workdir - Absolute path to the repository root (to normalize paths)
|
|
244
|
-
* @returns Source file paths (e.g. `["src/foo/bar.ts"]`)
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* ```typescript
|
|
248
|
-
* const sources = reverseMapTestToSource(["/repo/test/unit/foo/bar.test.ts"], "/repo");
|
|
249
|
-
* // Returns: ["src/foo/bar.ts"]
|
|
250
|
-
* ```
|
|
251
|
-
*/
|
|
252
|
-
export function reverseMapTestToSource(testFiles: string[], workdir: string): string[] {
|
|
253
|
-
const result: string[] = [];
|
|
254
|
-
const seenPaths = new Set<string>();
|
|
255
|
-
|
|
256
|
-
for (const testFile of testFiles) {
|
|
257
|
-
// Only process .test.ts files
|
|
258
|
-
if (!testFile.endsWith(".test.ts")) {
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// Normalize the path to be relative to workdir
|
|
263
|
-
let relativePath = testFile.startsWith(workdir) ? testFile.slice(workdir.length + 1) : testFile;
|
|
264
|
-
|
|
265
|
-
// Remove test/unit/ or test/integration/ prefix
|
|
266
|
-
if (relativePath.startsWith("test/unit/")) {
|
|
267
|
-
relativePath = relativePath.slice("test/unit/".length);
|
|
268
|
-
} else if (relativePath.startsWith("test/integration/")) {
|
|
269
|
-
relativePath = relativePath.slice("test/integration/".length);
|
|
270
|
-
} else {
|
|
271
|
-
continue; // Not a recognized test file pattern
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Replace .test.ts with .ts and add src/ prefix
|
|
275
|
-
const sourcePath = `src/${relativePath.replace(/\.test\.ts$/, ".ts")}`;
|
|
276
|
-
|
|
277
|
-
if (!seenPaths.has(sourcePath)) {
|
|
278
|
-
result.push(sourcePath);
|
|
279
|
-
seenPaths.add(sourcePath);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return result;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Injectable dependencies for testing.
|
|
288
|
-
* Allows tests to swap implementations without using mock.module(),
|
|
289
|
-
* which leaks across files in Bun 1.x due to shared module registry.
|
|
290
|
-
*
|
|
291
|
-
* Bun API wrappers use closures so that tests mocking Bun.Glob / Bun.file
|
|
292
|
-
* on the global namespace continue to work (closures evaluate Bun.* at
|
|
293
|
-
* call time, not at module initialisation time).
|
|
294
|
-
*
|
|
295
|
-
* @internal - test use only. Do not use in production code.
|
|
296
|
-
*/
|
|
297
|
-
export const _smartRunnerDeps = {
|
|
298
|
-
/** Wraps Bun.Glob construction — injectable for testing. */
|
|
299
|
-
glob: _bunDeps.glob,
|
|
300
|
-
/** Wraps Bun.file — injectable for testing. */
|
|
301
|
-
file: _bunDeps.file,
|
|
302
|
-
getChangedSourceFiles,
|
|
303
|
-
mapSourceToTests,
|
|
304
|
-
importGrepFallback,
|
|
305
|
-
buildSmartTestCommand,
|
|
306
|
-
reverseMapTestToSource,
|
|
307
|
-
};
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
// RE-ARCH: keep
|
|
2
|
-
/**
|
|
3
|
-
* Acceptance Verification Strategy (ADR-005, Phase 1)
|
|
4
|
-
*
|
|
5
|
-
* Runs acceptance tests from a feature directory test file.
|
|
6
|
-
* Extracted from src/pipeline/stages/acceptance.ts.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import path from "node:path";
|
|
10
|
-
import { getLogger } from "../../logger";
|
|
11
|
-
import type { IVerificationStrategy, VerifyContext, VerifyResult } from "../orchestrator-types";
|
|
12
|
-
import { makeFailResult, makePassResult, makeSkippedResult } from "../orchestrator-types";
|
|
13
|
-
|
|
14
|
-
/** Injectable deps for testability */
|
|
15
|
-
export const _acceptanceDeps = { spawn: Bun.spawn as typeof Bun.spawn };
|
|
16
|
-
|
|
17
|
-
function parseFailedACs(output: string): string[] {
|
|
18
|
-
const failed: string[] = [];
|
|
19
|
-
for (const line of output.split("\n")) {
|
|
20
|
-
if (line.includes("(fail)")) {
|
|
21
|
-
const m = line.match(/(AC-\d+):/i);
|
|
22
|
-
if (m) {
|
|
23
|
-
const id = m[1].toUpperCase();
|
|
24
|
-
if (!failed.includes(id)) failed.push(id);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return failed;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class AcceptanceStrategy implements IVerificationStrategy {
|
|
32
|
-
readonly name = "acceptance" as const;
|
|
33
|
-
|
|
34
|
-
async execute(ctx: VerifyContext): Promise<VerifyResult> {
|
|
35
|
-
const logger = getLogger();
|
|
36
|
-
|
|
37
|
-
if (!ctx.acceptanceTestPath) {
|
|
38
|
-
logger.warn("verify[acceptance]", "No acceptance test path provided — skipping", { storyId: ctx.storyId });
|
|
39
|
-
return makeSkippedResult(ctx.storyId, "acceptance");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const testPath = path.isAbsolute(ctx.acceptanceTestPath)
|
|
43
|
-
? ctx.acceptanceTestPath
|
|
44
|
-
: path.join(ctx.workdir, ctx.acceptanceTestPath);
|
|
45
|
-
|
|
46
|
-
const exists = await Bun.file(testPath).exists();
|
|
47
|
-
if (!exists) {
|
|
48
|
-
logger.warn("verify[acceptance]", "Acceptance test file not found — skipping", {
|
|
49
|
-
storyId: ctx.storyId,
|
|
50
|
-
testPath,
|
|
51
|
-
});
|
|
52
|
-
return makeSkippedResult(ctx.storyId, "acceptance");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const start = Date.now();
|
|
56
|
-
const timeoutMs = ctx.timeoutSeconds * 1000;
|
|
57
|
-
const proc = _acceptanceDeps.spawn(["bun", "test", testPath], {
|
|
58
|
-
cwd: ctx.workdir,
|
|
59
|
-
stdout: "pipe",
|
|
60
|
-
stderr: "pipe",
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
let timedOut = false;
|
|
64
|
-
const timeoutId = setTimeout(() => {
|
|
65
|
-
timedOut = true;
|
|
66
|
-
try {
|
|
67
|
-
proc.kill("SIGTERM");
|
|
68
|
-
} catch {
|
|
69
|
-
/* already exited */
|
|
70
|
-
}
|
|
71
|
-
setTimeout(() => {
|
|
72
|
-
try {
|
|
73
|
-
proc.kill("SIGKILL");
|
|
74
|
-
} catch {
|
|
75
|
-
/* already exited */
|
|
76
|
-
}
|
|
77
|
-
}, 5000);
|
|
78
|
-
}, timeoutMs);
|
|
79
|
-
|
|
80
|
-
const exitCode = await Promise.race([
|
|
81
|
-
proc.exited,
|
|
82
|
-
new Promise<number>((resolve) => setTimeout(() => resolve(124), timeoutMs + 6000)),
|
|
83
|
-
]);
|
|
84
|
-
clearTimeout(timeoutId);
|
|
85
|
-
const stdout = await Promise.race([
|
|
86
|
-
new Response(proc.stdout).text(),
|
|
87
|
-
new Promise<string>((resolve) => setTimeout(() => resolve(""), 3000)),
|
|
88
|
-
]);
|
|
89
|
-
const stderr = await Promise.race([
|
|
90
|
-
new Response(proc.stderr).text(),
|
|
91
|
-
new Promise<string>((resolve) => setTimeout(() => resolve(""), 3000)),
|
|
92
|
-
]);
|
|
93
|
-
const durationMs = Date.now() - start;
|
|
94
|
-
|
|
95
|
-
if (timedOut || exitCode === 124) {
|
|
96
|
-
logger.warn("verify[acceptance]", "Acceptance tests timed out", {
|
|
97
|
-
storyId: ctx.storyId,
|
|
98
|
-
timeoutSeconds: ctx.timeoutSeconds,
|
|
99
|
-
});
|
|
100
|
-
return makePassResult(ctx.storyId, "acceptance", { rawOutput: "TIMEOUT", durationMs });
|
|
101
|
-
}
|
|
102
|
-
const output = `${stdout}\n${stderr}`;
|
|
103
|
-
|
|
104
|
-
const failedACs = parseFailedACs(output);
|
|
105
|
-
|
|
106
|
-
if (exitCode === 0 && failedACs.length === 0) {
|
|
107
|
-
logger.info("verify[acceptance]", "All acceptance tests passed", { storyId: ctx.storyId });
|
|
108
|
-
return makePassResult(ctx.storyId, "acceptance", { rawOutput: output, durationMs });
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (failedACs.length === 0) {
|
|
112
|
-
// Test process failed but we couldn't parse AC IDs — treat as pass (setup error)
|
|
113
|
-
logger.warn("verify[acceptance]", "Tests failed but no AC IDs detected — treating as pass", {
|
|
114
|
-
storyId: ctx.storyId,
|
|
115
|
-
});
|
|
116
|
-
return makePassResult(ctx.storyId, "acceptance", { rawOutput: output, durationMs });
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
logger.error("verify[acceptance]", "Acceptance tests failed", {
|
|
120
|
-
storyId: ctx.storyId,
|
|
121
|
-
failedACs,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
return makeFailResult(ctx.storyId, "acceptance", "TEST_FAILURE", {
|
|
125
|
-
rawOutput: output,
|
|
126
|
-
failCount: failedACs.length,
|
|
127
|
-
failures: failedACs.map((acId) => ({
|
|
128
|
-
file: testPath,
|
|
129
|
-
testName: acId,
|
|
130
|
-
error: `Acceptance criterion ${acId} failed`,
|
|
131
|
-
stackTrace: [],
|
|
132
|
-
})),
|
|
133
|
-
durationMs,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// RE-ARCH: keep
|
|
2
|
-
/**
|
|
3
|
-
* Regression Verification Strategy (ADR-005, Phase 1)
|
|
4
|
-
*
|
|
5
|
-
* Runs the full test suite as a regression gate. Supports both inline
|
|
6
|
-
* (per-story) and deferred (end-of-run) modes via context flag.
|
|
7
|
-
*
|
|
8
|
-
* Extracted from src/execution/post-verify.ts and
|
|
9
|
-
* src/execution/lifecycle/run-regression.ts.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { getSafeLogger } from "../../logger";
|
|
13
|
-
import type { IVerificationStrategy, VerifyContext, VerifyResult } from "../orchestrator-types";
|
|
14
|
-
import { makeFailResult, makePassResult, makeSkippedResult } from "../orchestrator-types";
|
|
15
|
-
import { parseBunTestOutput } from "../parser";
|
|
16
|
-
import { fullSuite } from "../runners";
|
|
17
|
-
|
|
18
|
-
export class RegressionStrategy implements IVerificationStrategy {
|
|
19
|
-
readonly name: "regression" | "deferred-regression" = "regression";
|
|
20
|
-
|
|
21
|
-
async execute(ctx: VerifyContext): Promise<VerifyResult> {
|
|
22
|
-
const logger = getSafeLogger();
|
|
23
|
-
const config = ctx.config;
|
|
24
|
-
|
|
25
|
-
const enabled = config?.execution.regressionGate?.enabled ?? true;
|
|
26
|
-
if (!enabled) {
|
|
27
|
-
return makeSkippedResult(ctx.storyId, "regression");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
logger?.info("verify[regression]", "Running full-suite regression gate", { storyId: ctx.storyId });
|
|
31
|
-
|
|
32
|
-
const start = Date.now();
|
|
33
|
-
const result = await _regressionStrategyDeps.runVerification({
|
|
34
|
-
workdir: ctx.workdir,
|
|
35
|
-
expectedFiles: [],
|
|
36
|
-
command: ctx.testCommand,
|
|
37
|
-
timeoutSeconds: ctx.timeoutSeconds,
|
|
38
|
-
forceExit: config?.quality.forceExit,
|
|
39
|
-
detectOpenHandles: config?.quality.detectOpenHandles,
|
|
40
|
-
detectOpenHandlesRetries: config?.quality.detectOpenHandlesRetries,
|
|
41
|
-
timeoutRetryCount: 0,
|
|
42
|
-
gracePeriodMs: config?.quality.gracePeriodMs,
|
|
43
|
-
drainTimeoutMs: config?.quality.drainTimeoutMs,
|
|
44
|
-
shell: config?.quality.shell,
|
|
45
|
-
stripEnvVars: config?.quality.stripEnvVars,
|
|
46
|
-
});
|
|
47
|
-
const durationMs = Date.now() - start;
|
|
48
|
-
|
|
49
|
-
if (result.success) {
|
|
50
|
-
const parsed = result.output ? parseBunTestOutput(result.output) : { passed: 0, failed: 0, failures: [] };
|
|
51
|
-
return makePassResult(ctx.storyId, "regression", {
|
|
52
|
-
rawOutput: result.output,
|
|
53
|
-
passCount: parsed.passed,
|
|
54
|
-
durationMs,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Accept timeout as pass if configured (BUG-026)
|
|
59
|
-
if (result.status === "TIMEOUT" && (ctx.acceptOnTimeout ?? true)) {
|
|
60
|
-
logger?.warn("verify[regression]", "[BUG-026] Full-suite timed out (accepted as pass)", {
|
|
61
|
-
storyId: ctx.storyId,
|
|
62
|
-
});
|
|
63
|
-
return makePassResult(ctx.storyId, "regression", { durationMs });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (result.status === "TIMEOUT") {
|
|
67
|
-
return makeFailResult(ctx.storyId, "regression", "TIMEOUT", { rawOutput: result.output, durationMs });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const parsed = result.output ? parseBunTestOutput(result.output) : { passed: 0, failed: 0, failures: [] };
|
|
71
|
-
return makeFailResult(ctx.storyId, "regression", "TEST_FAILURE", {
|
|
72
|
-
rawOutput: result.output,
|
|
73
|
-
passCount: parsed.passed,
|
|
74
|
-
failCount: parsed.failed,
|
|
75
|
-
failures: parsed.failures,
|
|
76
|
-
durationMs,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const _regressionStrategyDeps = { runVerification: fullSuite };
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Deferred Regression Strategy — same logic as RegressionStrategy but
|
|
85
|
-
* reports strategy name as "deferred-regression" in VerifyResult so
|
|
86
|
-
* downstream code branching on strategy name works correctly.
|
|
87
|
-
*/
|
|
88
|
-
export class DeferredRegressionStrategy extends RegressionStrategy {
|
|
89
|
-
override readonly name = "deferred-regression" as const;
|
|
90
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
// RE-ARCH: keep
|
|
2
|
-
/**
|
|
3
|
-
* Scoped Verification Strategy (ADR-005, Phase 1)
|
|
4
|
-
*
|
|
5
|
-
* Runs tests scoped to files changed by the current story using the smart
|
|
6
|
-
* test runner. Falls back to full suite when no specific tests are mapped.
|
|
7
|
-
* Falls through to SKIPPED when in deferred mode and no tests are mapped.
|
|
8
|
-
*
|
|
9
|
-
* Extracted from src/pipeline/stages/verify.ts (lines 40-164).
|
|
10
|
-
* Must produce identical results to the existing verify stage.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { getLogger } from "../../logger";
|
|
14
|
-
import type { IVerificationStrategy, VerifyContext, VerifyResult } from "../orchestrator-types";
|
|
15
|
-
import { makeFailResult, makePassResult, makeSkippedResult } from "../orchestrator-types";
|
|
16
|
-
import { parseBunTestOutput } from "../parser";
|
|
17
|
-
import { regression } from "../runners";
|
|
18
|
-
import { _smartRunnerDeps } from "../smart-runner";
|
|
19
|
-
|
|
20
|
-
const DEFAULT_SMART_RUNNER_CONFIG = {
|
|
21
|
-
enabled: true,
|
|
22
|
-
testFilePatterns: ["test/**/*.test.ts"],
|
|
23
|
-
fallback: "import-grep" as const,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function coerceSmartRunner(val: unknown) {
|
|
27
|
-
if (val === undefined || val === true) return DEFAULT_SMART_RUNNER_CONFIG;
|
|
28
|
-
if (val === false) return { ...DEFAULT_SMART_RUNNER_CONFIG, enabled: false };
|
|
29
|
-
return val as typeof DEFAULT_SMART_RUNNER_CONFIG;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function buildScopedCommand(testFiles: string[], baseCommand: string, testScopedTemplate?: string): string {
|
|
33
|
-
if (testScopedTemplate) {
|
|
34
|
-
return testScopedTemplate.replace("{{files}}", testFiles.join(" "));
|
|
35
|
-
}
|
|
36
|
-
return _scopedDeps.buildSmartTestCommand(testFiles, baseCommand);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Returns true when the test command delegates to a monorepo orchestrator
|
|
41
|
-
* (Turborepo, Nx) that handles change-aware scoping natively.
|
|
42
|
-
*
|
|
43
|
-
* These tools use their own filter syntax (e.g. `--filter=...[HEAD~1]`,
|
|
44
|
-
* `nx affected`) — nax's smart test runner must not attempt to append
|
|
45
|
-
* file paths to such commands, as it would produce invalid syntax.
|
|
46
|
-
*/
|
|
47
|
-
export function isMonorepoOrchestratorCommand(command: string): boolean {
|
|
48
|
-
return /\bturbo\b/.test(command) || /\bnx\b/.test(command);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export class ScopedStrategy implements IVerificationStrategy {
|
|
52
|
-
readonly name = "scoped" as const;
|
|
53
|
-
|
|
54
|
-
async execute(ctx: VerifyContext): Promise<VerifyResult> {
|
|
55
|
-
const logger = getLogger();
|
|
56
|
-
const smartCfg = coerceSmartRunner(ctx.smartRunnerConfig);
|
|
57
|
-
const regressionMode = ctx.regressionMode ?? "deferred";
|
|
58
|
-
|
|
59
|
-
// Monorepo orchestrators (turbo, nx) handle change-aware scoping themselves.
|
|
60
|
-
// Skip nax's smart runner — appending file paths would produce invalid syntax.
|
|
61
|
-
// Also bypass deferred mode: run per-story so the orchestrator's own filter
|
|
62
|
-
// (e.g. --filter=...[HEAD~1]) can pick up the story's changes immediately.
|
|
63
|
-
const isMonorepoOrchestrator = isMonorepoOrchestratorCommand(ctx.testCommand);
|
|
64
|
-
|
|
65
|
-
let effectiveCommand = ctx.testCommand;
|
|
66
|
-
let isFullSuite = true;
|
|
67
|
-
|
|
68
|
-
if (smartCfg.enabled && ctx.storyGitRef && !isMonorepoOrchestrator) {
|
|
69
|
-
const sourceFiles = await _scopedDeps.getChangedSourceFiles(ctx.workdir, ctx.storyGitRef);
|
|
70
|
-
|
|
71
|
-
const pass1Files = await _scopedDeps.mapSourceToTests(sourceFiles, ctx.workdir);
|
|
72
|
-
if (pass1Files.length > 0) {
|
|
73
|
-
logger.info("verify[scoped]", `Pass 1: path convention matched ${pass1Files.length} test files`, {
|
|
74
|
-
storyId: ctx.storyId,
|
|
75
|
-
});
|
|
76
|
-
effectiveCommand = buildScopedCommand(pass1Files, ctx.testCommand, ctx.testScopedTemplate);
|
|
77
|
-
isFullSuite = false;
|
|
78
|
-
} else if (smartCfg.fallback === "import-grep") {
|
|
79
|
-
const pass2Files = await _scopedDeps.importGrepFallback(sourceFiles, ctx.workdir, smartCfg.testFilePatterns);
|
|
80
|
-
if (pass2Files.length > 0) {
|
|
81
|
-
logger.info("verify[scoped]", `Pass 2: import-grep matched ${pass2Files.length} test files`, {
|
|
82
|
-
storyId: ctx.storyId,
|
|
83
|
-
});
|
|
84
|
-
effectiveCommand = buildScopedCommand(pass2Files, ctx.testCommand, ctx.testScopedTemplate);
|
|
85
|
-
isFullSuite = false;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Defer to regression gate when no scoped tests found and mode is deferred.
|
|
91
|
-
// Exception: monorepo orchestrators run per-story (they carry their own change filter).
|
|
92
|
-
if (isFullSuite && regressionMode === "deferred" && !isMonorepoOrchestrator) {
|
|
93
|
-
logger.info("verify[scoped]", "No mapped tests — deferring to run-end (mode: deferred)", {
|
|
94
|
-
storyId: ctx.storyId,
|
|
95
|
-
});
|
|
96
|
-
return makeSkippedResult(ctx.storyId, "scoped");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (isFullSuite && !isMonorepoOrchestrator) {
|
|
100
|
-
logger.info("verify[scoped]", "No mapped tests — falling back to full suite", { storyId: ctx.storyId });
|
|
101
|
-
} else if (isMonorepoOrchestrator) {
|
|
102
|
-
logger.info("verify[scoped]", "Monorepo orchestrator detected — delegating scoping to tool", {
|
|
103
|
-
storyId: ctx.storyId,
|
|
104
|
-
command: effectiveCommand,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const start = Date.now();
|
|
109
|
-
const result = await _scopedDeps.regression({
|
|
110
|
-
workdir: ctx.workdir,
|
|
111
|
-
command: effectiveCommand,
|
|
112
|
-
timeoutSeconds: ctx.timeoutSeconds,
|
|
113
|
-
acceptOnTimeout: ctx.acceptOnTimeout ?? true,
|
|
114
|
-
});
|
|
115
|
-
const durationMs = Date.now() - start;
|
|
116
|
-
|
|
117
|
-
if (result.success) {
|
|
118
|
-
const parsed = result.output ? parseBunTestOutput(result.output) : { passed: 0, failed: 0, failures: [] };
|
|
119
|
-
return makePassResult(ctx.storyId, "scoped", {
|
|
120
|
-
rawOutput: result.output,
|
|
121
|
-
passCount: parsed.passed,
|
|
122
|
-
durationMs,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (result.status === "TIMEOUT") {
|
|
127
|
-
return makeFailResult(ctx.storyId, "scoped", "TIMEOUT", {
|
|
128
|
-
rawOutput: result.output,
|
|
129
|
-
durationMs,
|
|
130
|
-
countsTowardEscalation: false,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const parsed = result.output ? parseBunTestOutput(result.output) : { passed: 0, failed: 0, failures: [] };
|
|
135
|
-
return makeFailResult(ctx.storyId, "scoped", "TEST_FAILURE", {
|
|
136
|
-
rawOutput: result.output,
|
|
137
|
-
passCount: parsed.passed,
|
|
138
|
-
failCount: parsed.failed,
|
|
139
|
-
failures: parsed.failures,
|
|
140
|
-
durationMs,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Injectable deps for testing.
|
|
147
|
-
*/
|
|
148
|
-
export const _scopedDeps = {
|
|
149
|
-
getChangedSourceFiles: _smartRunnerDeps.getChangedSourceFiles,
|
|
150
|
-
mapSourceToTests: _smartRunnerDeps.mapSourceToTests,
|
|
151
|
-
importGrepFallback: _smartRunnerDeps.importGrepFallback,
|
|
152
|
-
buildSmartTestCommand: _smartRunnerDeps.buildSmartTestCommand,
|
|
153
|
-
regression,
|
|
154
|
-
};
|