@polymorphism-tech/morph-spec 10.12.1 → 11.0.0
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/CLAUDE.md +27 -57
- package/README.md +51 -340
- package/bin/morph-spec.js +22 -373
- package/docs/CHEATSHEET.md +37 -166
- package/docs/QUICKSTART.md +14 -74
- package/framework/CLAUDE.md +15 -26
- package/framework/MORPH.md +34 -101
- package/framework/agents.json +8 -8
- package/framework/commands/morph-apply.md +5 -5
- package/framework/commands/morph-infra.md +1 -1
- package/framework/docs/CLI.md +74 -886
- package/framework/evals/review-checklist.md +14 -14
- package/framework/hooks/README.md +21 -189
- package/framework/hooks/claude-code/core/README.md +2 -5
- package/framework/hooks/claude-code/core/conventional-commit.js +2 -2
- package/framework/hooks/claude-code/core/denylist.json +3 -3
- package/framework/hooks/claude-code/core/graph-refresh-kick.js +2 -2
- package/framework/hooks/claude-code/core/masked-exit.js +6 -6
- package/framework/hooks/claude-code/core/pre-bash-denylist.js +2 -2
- package/framework/hooks/claude-code/core/protect-spec-files.js +17 -61
- package/framework/hooks/claude-code/core/stack-changed.js +35 -0
- package/framework/hooks/claude-code/core/validate-completion.js +32 -87
- package/framework/hooks/shared/{heavy-command.js → command-kind.js} +6 -79
- package/framework/hooks/shared/command-tokens.js +0 -139
- package/framework/hooks/shared/contract.js +14 -0
- package/framework/hooks/shared/feature-slug.js +21 -0
- package/framework/hooks/shared/frontend-locations.js +0 -1
- package/framework/hooks/shared/git-paths.js +0 -15
- package/framework/hooks/shared/graph-freshness.js +0 -19
- package/framework/hooks/shared/hook-response.js +0 -7
- package/framework/hooks/shared/morph-cli.js +2 -81
- package/framework/hooks/shared/owner-words.js +2 -120
- package/framework/hooks/shared/payload-utils.js +0 -39
- package/framework/hooks/shared/report-progress.js +7 -101
- package/framework/hooks/statusline.js +16 -60
- package/framework/mcp/registry.json +2 -2
- package/framework/rules/ai-agents-standards.md +1 -1
- package/framework/rules/asaas-standards.md +1 -1
- package/framework/rules/ef-standards.md +1 -1
- package/framework/rules/gsap-standards.md +1 -1
- package/framework/rules/hangfire-standards.md +1 -1
- package/framework/rules/implement-report.md +3 -3
- package/framework/rules/neon-auth-standards.md +1 -1
- package/framework/rules/nextjs-standards.md +1 -1
- package/framework/rules/plan-grammar.md +13 -11
- package/framework/rules/resend-standards.md +1 -1
- package/framework/rules/ui-design.md +4 -0
- package/framework/schemas/config.schema.json +95 -310
- package/framework/skills/README.md +12 -32
- package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
- package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
- package/framework/skills/core/morph-apply/SKILL.md +21 -46
- package/framework/skills/core/morph-plan/SKILL.md +28 -63
- package/framework/skills/core/morph-uiux/SKILL.md +23 -25
- package/framework/{templates/docs/ui-mockups.md → skills/core/morph-uiux/references/mockups.md} +4 -4
- package/framework/standards/STANDARDS.json +10 -11
- package/framework/standards/STANDARDS.meta.json +1 -1
- package/framework/standards/ai-agents/evals-with-cache.md +18 -32
- package/framework/standards/ai-agents/observability-patterns.md +2 -2
- package/framework/standards/architecture/code-comments.md +2 -5
- package/framework/standards/architecture/engineering-lens.md +1 -1
- package/framework/standards/backend/dotnet/testing.md +4 -4
- package/framework/standards/frontend/nextjs/lint.md +24 -10
- package/framework/standards/frontend/nextjs/testing.md +2 -2
- package/framework/standards/infrastructure/docker/local-compose-isolation.md +14 -30
- package/framework/templates/CLAUDE.md.core.guide.md +2 -2
- package/framework/templates/README.md +1 -1
- package/framework/templates/REGISTRY.json +3 -33
- package/framework/templates/docs/plan.md +3 -2
- package/framework/templates/dotnet/ai-kit/README.md +2 -4
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheMissException.cs +1 -1
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalFixture.cs +1 -1
- package/package.json +1 -2
- package/src/commands/graph/explain.js +2 -1
- package/src/commands/graph/status.js +2 -1
- package/src/commands/mcp/mcp-setup.js +1 -2
- package/src/commands/project/doctor.js +5 -341
- package/src/commands/project/env.js +21 -52
- package/src/commands/project/init-contract.js +47 -0
- package/src/commands/project/init.js +36 -66
- package/src/commands/project/stack-scan.js +1 -1
- package/src/commands/project/update.js +15 -50
- package/src/commands/validation/check.js +128 -0
- package/src/commands/validation/plan-check.js +41 -64
- package/src/commands/validation/prove-red.js +1 -1
- package/src/core/paths/output-schema.js +0 -22
- package/src/core/templates/template-renderer.js +0 -14
- package/src/lib/ai/ai-project-scan.js +1 -6
- package/src/lib/check/attempts.js +38 -0
- package/src/lib/check/signals.js +145 -0
- package/src/lib/config/project-config.js +13 -0
- package/src/lib/contract/apply.js +62 -0
- package/src/lib/contract/defaults.js +96 -0
- package/src/lib/contract/merge.js +79 -0
- package/src/lib/contract/ports.js +43 -0
- package/src/lib/contract/scan.js +102 -0
- package/src/lib/detectors/claude-config-detector.js +7 -0
- package/src/lib/{procs → detectors}/mcp-config.js +1 -37
- package/src/lib/diff/diff-lines.js +64 -0
- package/src/lib/generators/architecture-scanner.js +1 -1
- package/src/lib/generators/scaffold-generator.js +0 -7
- package/src/lib/git/default-branch.js +0 -122
- package/src/lib/graph/diff-tree.js +2 -1
- package/src/lib/graph/god-nodes.js +2 -1
- package/src/lib/graph/graphify-runtime.js +0 -1
- package/src/lib/graph/graphifyignore.js +1 -1
- package/src/lib/graph/sanitize.js +2 -8
- package/src/lib/installers/memory-installer.js +15 -30
- package/src/lib/installers/stack-sync.js +16 -9
- package/src/lib/plan/checks.js +20 -64
- package/src/lib/plan/media.js +1 -1
- package/src/lib/plan/plan-parser.js +5 -5
- package/src/lib/review-reports.js +3 -77
- package/src/lib/scan/worktree-dirs.js +3 -0
- package/src/lib/specs/adr-index.js +2 -2
- package/src/lib/stack/dotnet-build-ignores.js +10 -2
- package/src/lib/stack/stack-scan.js +2 -2
- package/src/lib/stack-filter.js +3 -2
- package/src/lib/tests-audit/audit.js +1 -1
- package/src/scripts/setup-infra.js +6 -59
- package/src/utils/agents-installer.js +1 -34
- package/src/utils/atomic-json.js +27 -0
- package/src/utils/file-copier.js +4 -12
- package/src/utils/hooks-installer.js +9 -107
- package/claude-plugin.json +0 -14
- package/framework/commands/morph-archive.md +0 -46
- package/framework/commands/morph-hotfix.md +0 -17
- package/framework/commands/morph-preflight.md +0 -180
- package/framework/commands/morph-review.md +0 -15
- package/framework/commands/morph-status.md +0 -37
- package/framework/hooks/claude-code/core/block-destructive-worktree-removal.js +0 -80
- package/framework/hooks/claude-code/core/block-raw-worktree-add.js +0 -72
- package/framework/hooks/claude-code/core/enforce-phase-writes.js +0 -100
- package/framework/hooks/claude-code/core/gate-guard.js +0 -148
- package/framework/hooks/claude-code/core/heavy-gate.js +0 -78
- package/framework/hooks/claude-code/core/heavy-release.js +0 -23
- package/framework/hooks/claude-code/core/loop-detect.js +0 -79
- package/framework/hooks/claude-code/core/state-sync.js +0 -214
- package/framework/hooks/claude-code/core/telemetry-log.js +0 -259
- package/framework/hooks/claude-code/core/test-budget.js +0 -29
- package/framework/hooks/claude-code/core/worktree-context.js +0 -249
- package/framework/hooks/claude-code/core/worktree-create.js +0 -119
- package/framework/hooks/claude-code/core/worktree-env-inject.js +0 -68
- package/framework/hooks/claude-code/core/worktree-remove.js +0 -55
- package/framework/hooks/shared/build-check.js +0 -120
- package/framework/hooks/shared/claim-registry.js +0 -125
- package/framework/hooks/shared/e2e-check.js +0 -1022
- package/framework/hooks/shared/feature-locator.js +0 -82
- package/framework/hooks/shared/gate-event.js +0 -18
- package/framework/hooks/shared/gate-question.js +0 -20
- package/framework/hooks/shared/heavy-config.js +0 -113
- package/framework/hooks/shared/heavy-holders.js +0 -85
- package/framework/hooks/shared/heavy-slots.js +0 -280
- package/framework/hooks/shared/host-services.js +0 -440
- package/framework/hooks/shared/next-step.js +0 -181
- package/framework/hooks/shared/redact-secrets.js +0 -44
- package/framework/hooks/shared/reparse-scan.js +0 -40
- package/framework/hooks/shared/state-reader.js +0 -220
- package/framework/hooks/shared/state-writer.js +0 -112
- package/framework/hooks/shared/telemetry-logger.js +0 -101
- package/framework/hooks/shared/transcript-usage.js +0 -58
- package/framework/hooks/shared/worktree-root.js +0 -71
- package/framework/phases.json +0 -92
- package/framework/schemas/feature.schema.json +0 -242
- package/framework/skills/core/morph-apply/references/hotfix.md +0 -46
- package/framework/skills/core/morph-apply/references/machine.md +0 -30
- package/framework/skills/core/morph-apply/references/review.md +0 -77
- package/framework/skills/core/morph-plan/references/critique.md +0 -51
- package/framework/skills/core/morph-plan/references/interview.md +0 -37
- package/framework/templates/state.template.json +0 -17
- package/src/commands/dashboard/dashboard.js +0 -74
- package/src/commands/e2e/e2e.js +0 -400
- package/src/commands/observability/cost.js +0 -283
- package/src/commands/project/branch.js +0 -129
- package/src/commands/project/claim.js +0 -132
- package/src/commands/project/doctor-procs.js +0 -162
- package/src/commands/project/fleet.js +0 -66
- package/src/commands/project/heavy.js +0 -81
- package/src/commands/project/install-plugin-cmd.js +0 -27
- package/src/commands/project/status.js +0 -61
- package/src/commands/project/worktree.js +0 -1234
- package/src/commands/state/advance.js +0 -248
- package/src/commands/state/approve.js +0 -303
- package/src/commands/state/archive.js +0 -231
- package/src/commands/state/auto-approval.js +0 -67
- package/src/commands/state/create.js +0 -274
- package/src/commands/state/delete.js +0 -192
- package/src/commands/state/finish.js +0 -1247
- package/src/commands/state/gate-check.js +0 -244
- package/src/commands/state/gate-decision.js +0 -122
- package/src/commands/state/list.js +0 -244
- package/src/commands/state/next.js +0 -24
- package/src/commands/state/recap.js +0 -80
- package/src/commands/state/report-check.js +0 -244
- package/src/commands/state/retype.js +0 -110
- package/src/commands/validation/verify.js +0 -421
- package/src/core/state/feature-identity.js +0 -10
- package/src/core/state/gate-order.js +0 -23
- package/src/core/state/lifecycle-audit.js +0 -171
- package/src/core/state/state-manager.js +0 -523
- package/src/core/templates/template-seed.js +0 -21
- package/src/core/work-types.js +0 -44
- package/src/dashboard/app/App.jsx +0 -84
- package/src/dashboard/app/components/ActivityFeed.jsx +0 -166
- package/src/dashboard/app/components/CommandPalette.jsx +0 -144
- package/src/dashboard/app/components/DetailPanel.jsx +0 -43
- package/src/dashboard/app/components/EntityLink.jsx +0 -42
- package/src/dashboard/app/components/ErrorBoundary.jsx +0 -47
- package/src/dashboard/app/components/FlowGraph.jsx +0 -19
- package/src/dashboard/app/components/GatePauses.jsx +0 -116
- package/src/dashboard/app/components/KnowledgeMarkdown.jsx +0 -42
- package/src/dashboard/app/components/Markdown.jsx +0 -38
- package/src/dashboard/app/components/PhaseRail.jsx +0 -100
- package/src/dashboard/app/components/SearchFilter.jsx +0 -36
- package/src/dashboard/app/components/SessionMap.jsx +0 -77
- package/src/dashboard/app/components/Sidebar.jsx +0 -147
- package/src/dashboard/app/hooks/useMorphQuery.js +0 -44
- package/src/dashboard/app/hooks/usePref.js +0 -34
- package/src/dashboard/app/lib/format.js +0 -69
- package/src/dashboard/app/lib/phases.js +0 -75
- package/src/dashboard/app/lib/project.js +0 -38
- package/src/dashboard/app/main.jsx +0 -13
- package/src/dashboard/app/pages/Activity.jsx +0 -28
- package/src/dashboard/app/pages/AgentMap.jsx +0 -363
- package/src/dashboard/app/pages/FeatureDetail.jsx +0 -579
- package/src/dashboard/app/pages/Features.jsx +0 -393
- package/src/dashboard/app/pages/Guide.jsx +0 -145
- package/src/dashboard/app/pages/HookInspector.jsx +0 -444
- package/src/dashboard/app/pages/PhasePipeline.jsx +0 -273
- package/src/dashboard/app/pages/Portfolio.jsx +0 -190
- package/src/dashboard/app/pages/RulesMap.jsx +0 -285
- package/src/dashboard/app/pages/SkillsLibrary.jsx +0 -468
- package/src/dashboard/app/pages/Standards.jsx +0 -392
- package/src/dashboard/app/styles/index.css +0 -187
- package/src/dashboard/index.html +0 -14
- package/src/dashboard/package.json +0 -32
- package/src/dashboard/scanner/activity-scanner.js +0 -321
- package/src/dashboard/scanner/agents-scanner.js +0 -67
- package/src/dashboard/scanner/docs-scanner.js +0 -34
- package/src/dashboard/scanner/feature-status.js +0 -7
- package/src/dashboard/scanner/features-scanner.js +0 -397
- package/src/dashboard/scanner/hooks-scanner.js +0 -96
- package/src/dashboard/scanner/index.js +0 -21
- package/src/dashboard/scanner/phases-scanner.js +0 -14
- package/src/dashboard/scanner/portfolio.js +0 -129
- package/src/dashboard/scanner/project-api.js +0 -160
- package/src/dashboard/scanner/rules-scanner.js +0 -46
- package/src/dashboard/scanner/skills-scanner.js +0 -104
- package/src/dashboard/scanner/standards-scanner.js +0 -38
- package/src/dashboard/vite-plugin-morph-data.js +0 -120
- package/src/dashboard/vite.config.js +0 -26
- package/src/lib/ci/ci-verify.js +0 -30
- package/src/lib/ci/github-ci.js +0 -52
- package/src/lib/ci/pr-checks.js +0 -76
- package/src/lib/e2e/applicability.js +0 -39
- package/src/lib/e2e/compose-env.js +0 -80
- package/src/lib/e2e/stack-teardown.js +0 -96
- package/src/lib/git/branch-classifier.js +0 -104
- package/src/lib/git/evidence-staleness.js +0 -40
- package/src/lib/git/gh.js +0 -15
- package/src/lib/git/pending-prs.js +0 -58
- package/src/lib/git/pr-files.js +0 -31
- package/src/lib/git/pr-index.js +0 -39
- package/src/lib/git/tree-fingerprint.js +0 -58
- package/src/lib/git/tree-state.js +0 -125
- package/src/lib/heavy/cleanup.js +0 -72
- package/src/lib/heavy/gate.js +0 -168
- package/src/lib/heavy/live-stacks.js +0 -64
- package/src/lib/heavy/reclaim.js +0 -107
- package/src/lib/heavy/watchdog.js +0 -46
- package/src/lib/next-step.js +0 -12
- package/src/lib/plan/critique.js +0 -67
- package/src/lib/plan/plan-template.js +0 -18
- package/src/lib/procs/classify.js +0 -91
- package/src/lib/procs/list.js +0 -124
- package/src/lib/procs/prune.js +0 -47
- package/src/lib/procs/wslconfig.js +0 -70
- package/src/lib/projects/registry.js +0 -121
- package/src/lib/recap/piper.js +0 -36
- package/src/lib/recap/recap.js +0 -259
- package/src/lib/review-confirmation.js +0 -66
- package/src/lib/risk/diff-risk.js +0 -137
- package/src/lib/risk-detector.js +0 -638
- package/src/lib/specs/design-seed.js +0 -18
- package/src/lib/specs/screen-checklist.js +0 -315
- package/src/lib/stack/stack-profile.js +0 -69
- package/src/lib/tasks/eval-node.js +0 -293
- package/src/lib/tasks/linux-runner.js +0 -200
- package/src/lib/tasks/test-nodes.js +0 -414
- package/src/lib/tasks/test-runner.js +0 -569
- package/src/lib/telemetry/metrics.js +0 -384
- package/src/lib/telemetry/telemetry-reader.js +0 -276
- package/src/lib/telemetry/verify-event.js +0 -57
- package/src/lib/validators/code-budget/code-budget-validator.js +0 -170
- package/src/lib/validators/contracts/contract-compliance-validator.js +0 -219
- package/src/lib/validators/nextjs/next-component-validator.js +0 -142
- package/src/lib/validators/packages/package-validator.js +0 -310
- package/src/lib/validators/reuse/reuse-validator.js +0 -202
- package/src/lib/validators/reuse/symbol-scanner.js +0 -64
- package/src/lib/validators/validation-runner.js +0 -188
- package/src/lib/validators/verify-cache.js +0 -63
- package/src/lib/validators/verify-runner.js +0 -971
- package/src/lib/verify/affected.js +0 -143
- package/src/lib/verify/detached.js +0 -159
- package/src/lib/view/feature-html.js +0 -480
- package/src/lib/view/feature-page.client.js +0 -109
- package/src/lib/view/feature-page.css +0 -278
- package/src/lib/view/feature-view.js +0 -113
- package/src/lib/view/flow-layers.js +0 -79
- package/src/lib/view/flow-svg.js +0 -63
- package/src/lib/view/tokens.css +0 -18
- package/src/lib/work-type-detector.js +0 -81
- package/src/lib/worktree/dirs.js +0 -3
- package/src/lib/worktree/docker-audit.js +0 -175
- package/src/lib/worktree/env-allocator.js +0 -177
- package/src/lib/worktree/feature-truth.js +0 -145
- package/src/lib/worktree/finish-backup.js +0 -529
- package/src/lib/worktree/fleet-scanner.js +0 -223
- package/src/lib/worktree/ignored-triage.js +0 -136
- package/src/lib/worktree/vscode-settings.js +0 -112
- package/src/lib/worktree/worktree-audit.js +0 -323
- package/src/lib/worktree/worktree-include.js +0 -44
- package/src/scripts/install-plugin.js +0 -114
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
// The Docker Desktop bind mount is case-insensitive (9p/gRPC-FUSE), so the tree is
|
|
2
|
-
// mounted read-only at /src and COPIED to the container's own filesystem at /work:
|
|
3
|
-
// running on the mount would hide exactly the casing defects this runner exists for.
|
|
4
|
-
import { createHash } from 'crypto';
|
|
5
|
-
import { resolve } from 'path';
|
|
6
|
-
|
|
7
|
-
import { defaultExec, isDockerAvailable } from '../../../framework/hooks/shared/e2e-check.js';
|
|
8
|
-
import { WORKTREES_DIR, LEGACY_WORKTREES_DIR } from '../worktree/dirs.js';
|
|
9
|
-
|
|
10
|
-
export const LINUX_DEFAULT_IMAGE = 'mcr.microsoft.com/dotnet/sdk:10.0';
|
|
11
|
-
|
|
12
|
-
const SRC_MOUNT = '/src';
|
|
13
|
-
const WORK_DIR = '/work';
|
|
14
|
-
|
|
15
|
-
// Deliberately noisy: a delimiter that could occur in real test output would
|
|
16
|
-
// attribute failures to the wrong suite.
|
|
17
|
-
export const NODE_START = '@@MORPH-NODE-START@@';
|
|
18
|
-
export const NODE_EXIT = '@@MORPH-NODE-EXIT@@';
|
|
19
|
-
|
|
20
|
-
// Worktree dirs are anchored at the root (`./name`); build artifacts nest anywhere.
|
|
21
|
-
// A worktree is another feature's checkout and must never be copied.
|
|
22
|
-
export const COPY_EXCLUDES = [
|
|
23
|
-
'node_modules',
|
|
24
|
-
'bin',
|
|
25
|
-
'obj',
|
|
26
|
-
'.git',
|
|
27
|
-
`./${WORKTREES_DIR}`,
|
|
28
|
-
`./${LEGACY_WORKTREES_DIR}`,
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
function shq(value) {
|
|
32
|
-
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// A missing daemon is a usage error, never a skipped node: a skip would read
|
|
36
|
-
// "could not check on Linux" as green.
|
|
37
|
-
export function checkLinuxPreconditions({ projectPath, skipTests, exec = defaultExec }) {
|
|
38
|
-
if (skipTests) {
|
|
39
|
-
return '--linux com --skip-tests se anulam: a flag existe para RODAR a suíte em Linux';
|
|
40
|
-
}
|
|
41
|
-
if (!isDockerAvailable(projectPath, exec)) {
|
|
42
|
-
return '--linux exige Docker e o daemon não respondeu — '
|
|
43
|
-
+ 'rode onde ele exista (nunca reportamos "não deu para checar no Linux" como verde)';
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// e2e nodes are refused by name, never dropped: a suite that disappears from the
|
|
49
|
-
// report reads as green.
|
|
50
|
-
function partitionNodes(nodes) {
|
|
51
|
-
const runnable = [];
|
|
52
|
-
const refused = [];
|
|
53
|
-
for (const node of nodes) {
|
|
54
|
-
if (node.e2e) {
|
|
55
|
-
refused.push({
|
|
56
|
-
id: node.id,
|
|
57
|
-
skipped: true,
|
|
58
|
-
reason: 'nó e2e não roda dentro do container do --linux (docker-em-docker fora de escopo)',
|
|
59
|
-
output: '',
|
|
60
|
-
exitCode: null,
|
|
61
|
-
durationMs: 0,
|
|
62
|
-
});
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
runnable.push(node);
|
|
66
|
-
}
|
|
67
|
-
return { runnable, refused };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// No `set -e` around the nodes: one red suite must not cancel the ones after it.
|
|
71
|
-
export function buildContainerScript({ nodes }) {
|
|
72
|
-
const excludes = COPY_EXCLUDES.map((e) => `--exclude=${e}`).join(' ');
|
|
73
|
-
const lines = [
|
|
74
|
-
'set -u',
|
|
75
|
-
`mkdir -p ${WORK_DIR}`,
|
|
76
|
-
`tar -C ${SRC_MOUNT} ${excludes} -cf - . | tar -C ${WORK_DIR} -xf -`,
|
|
77
|
-
];
|
|
78
|
-
|
|
79
|
-
for (const node of nodes) {
|
|
80
|
-
const dir = `${WORK_DIR}/${node.cwd || '.'}`;
|
|
81
|
-
// `$?` is captured into its own variable: sharing an echo with `$(date)` can
|
|
82
|
-
// report the timestamp's exit code as the suite's.
|
|
83
|
-
lines.push(`__ms=$(date +%s 2>/dev/null); echo "${NODE_START} ${node.id} $__ms"`);
|
|
84
|
-
lines.push(`cd ${shq(dir)} && ${node.command}`);
|
|
85
|
-
lines.push(`__code=$?; __me=$(date +%s 2>/dev/null); echo "${NODE_EXIT} ${node.id} $__code $__me"`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return lines.join('\n');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function buildLinuxArgv({ projectPath, image, script, runId = null }) {
|
|
92
|
-
return [
|
|
93
|
-
'run', '--rm',
|
|
94
|
-
...(runId ? ['--label', `${LABEL_RUN}=${runId}`, '--label', `${LABEL_ROOT}=${rootHash(projectPath)}`] : []),
|
|
95
|
-
'-v', `${resolve(projectPath).replace(/\\/g, '/')}:${SRC_MOUNT}:ro`,
|
|
96
|
-
'-w', WORK_DIR,
|
|
97
|
-
image,
|
|
98
|
-
'sh', '-c', script,
|
|
99
|
-
];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// A node whose exit marker never arrived did not pass: the container died mid-run.
|
|
103
|
-
function splitByMarkers(output, nodes) {
|
|
104
|
-
const text = String(output || '');
|
|
105
|
-
const escape = (v) => String(v).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
106
|
-
return nodes.map((node) => {
|
|
107
|
-
const startRe = new RegExp(`${escape(NODE_START)} ${escape(node.id)}(?: (\\d+))?`);
|
|
108
|
-
const exitRe = new RegExp(`${escape(NODE_EXIT)} ${escape(node.id)} (-?\\d+)(?: (\\d+))?`);
|
|
109
|
-
const startMatch = startRe.exec(text);
|
|
110
|
-
if (!startMatch) {
|
|
111
|
-
return {
|
|
112
|
-
id: node.id,
|
|
113
|
-
exitCode: null,
|
|
114
|
-
durationMs: null,
|
|
115
|
-
output: '',
|
|
116
|
-
reason: 'o container terminou antes deste nó — nenhum veredito foi observado',
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
const rest = text.slice(startMatch.index + startMatch[0].length);
|
|
120
|
-
const exitMatch = exitRe.exec(rest);
|
|
121
|
-
const body = (exitMatch ? rest.slice(0, exitMatch.index) : rest).replace(/^\r?\n/, '').trimEnd();
|
|
122
|
-
if (!exitMatch) {
|
|
123
|
-
return {
|
|
124
|
-
id: node.id,
|
|
125
|
-
exitCode: null,
|
|
126
|
-
durationMs: null,
|
|
127
|
-
output: body,
|
|
128
|
-
reason: 'o container terminou sem reportar o código de saída deste nó',
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
// null is UNKNOWN, never 0: an image without `date` did not run in zero ms.
|
|
132
|
-
const durationMs = startMatch[1] && exitMatch[2]
|
|
133
|
-
? (Number(exitMatch[2]) - Number(startMatch[1])) * 1000
|
|
134
|
-
: null;
|
|
135
|
-
return { id: node.id, exitCode: Number(exitMatch[1]), durationMs, output: body, reason: null };
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Runs every runnable node in ONE container and returns raw per-node results,
|
|
141
|
-
* unjudged: verify-runner judges container and host runs with the same code.
|
|
142
|
-
*/
|
|
143
|
-
export function runLinuxSuite({ projectPath, nodes, image, timeout, exec = defaultExec }) {
|
|
144
|
-
const { runnable, refused } = partitionNodes(nodes);
|
|
145
|
-
const declared = runnable.map((n) => n.linuxImage).filter(Boolean);
|
|
146
|
-
const resolvedImage = image || declared[0] || LINUX_DEFAULT_IMAGE;
|
|
147
|
-
const environment = { kind: 'linux-container', image: resolvedImage };
|
|
148
|
-
|
|
149
|
-
if (runnable.length === 0) {
|
|
150
|
-
return { results: refused, environment, argv: [], script: '', containerCode: null };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const script = buildContainerScript({ nodes: runnable });
|
|
154
|
-
const runId = `${process.pid}-${Date.now().toString(36)}`;
|
|
155
|
-
const argv = buildLinuxArgv({ projectPath, image: resolvedImage, script, runId });
|
|
156
|
-
let run;
|
|
157
|
-
try {
|
|
158
|
-
run = exec('docker', argv, { cwd: projectPath, timeout });
|
|
159
|
-
} finally {
|
|
160
|
-
reapLabeledContainers({ runId, exec, cwd: projectPath });
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const results = splitByMarkers(run.output, runnable).map((r) =>
|
|
164
|
-
r.exitCode === null && !r.reason
|
|
165
|
-
? { ...r, reason: 'o container não reportou este nó' }
|
|
166
|
-
: r
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
const nothingRan = results.every((r) => r.exitCode === null);
|
|
170
|
-
const enriched = results.map((r) =>
|
|
171
|
-
r.exitCode === null && nothingRan
|
|
172
|
-
? { ...r, reason: `${r.reason} (container saiu com ${run.code}): ${tail(run.output)}` }
|
|
173
|
-
: r
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
return { results: [...enriched, ...refused], environment, argv, script, containerCode: run.code };
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export const LABEL_RUN = 'morph-spec.verify';
|
|
180
|
-
export const LABEL_ROOT = 'morph-spec.root';
|
|
181
|
-
|
|
182
|
-
export function rootHash(projectPath) {
|
|
183
|
-
const root = resolve(projectPath).replace(/\\/g, '/');
|
|
184
|
-
const key = process.platform === 'win32' ? root.toLowerCase() : root;
|
|
185
|
-
return createHash('sha1').update(key).digest('hex').slice(0, 12);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// A timeout kills the docker client, not the container: `--rm` never fires for it.
|
|
189
|
-
export function reapLabeledContainers({ runId, exec, cwd }) {
|
|
190
|
-
try {
|
|
191
|
-
const listed = exec('docker', ['ps', '-aq', '--filter', `label=${LABEL_RUN}=${runId}`], { cwd, timeout: 15_000 });
|
|
192
|
-
if (listed.code !== 0) return;
|
|
193
|
-
const ids = String(listed.output ?? '').split(/\s+/).filter((id) => /^[0-9a-f]{6,64}$/i.test(id));
|
|
194
|
-
if (ids.length) exec('docker', ['rm', '-f', ...ids], { cwd, timeout: 30_000 });
|
|
195
|
-
} catch { /* limpeza best-effort: nunca muda o veredito da suíte */ }
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function tail(output, lines = 5) {
|
|
199
|
-
return String(output || '').split('\n').slice(-lines).join('\n').trim();
|
|
200
|
-
}
|
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'fs';
|
|
2
|
-
import { join, resolve, relative, sep } from 'path';
|
|
3
|
-
|
|
4
|
-
import { resolveTestPlan, readMorphConfig, isInside } from './test-runner.js';
|
|
5
|
-
import { EVAL_RUNNER, evalBlockProblem } from './eval-node.js';
|
|
6
|
-
import { atomicWriteJson, CONFIG_FILE_NAME } from '../../core/state/state-manager.js';
|
|
7
|
-
import { PACKAGE_LOCATIONS } from '../detectors/index.js';
|
|
8
|
-
|
|
9
|
-
/** `none` yields an UNKNOWN count, never a fabricated zero. */
|
|
10
|
-
export const TEST_RUNNERS = ['dotnet', 'vitest', 'jest', 'node-test', 'playwright', 'none', EVAL_RUNNER];
|
|
11
|
-
|
|
12
|
-
// A count is a baseline only where it stays still: dotnet/vitest/jest/playwright grow every
|
|
13
|
-
// slice, so their baseline only warned or blocked a deliberate deletion.
|
|
14
|
-
const BASELINE_RUNNERS = ['node-test', EVAL_RUNNER];
|
|
15
|
-
|
|
16
|
-
export function keepsBaseline(runner) {
|
|
17
|
-
return BASELINE_RUNNERS.includes(runner);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const TEST_NODE_ID_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
21
|
-
|
|
22
|
-
const FALLBACK_NODE_ID = 'default';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* null means "no filter given"; `{tokens: []}` means "filtered and selected nothing",
|
|
26
|
-
* which is a usage error, not a full run.
|
|
27
|
-
* @returns {{ raw: string, tokens: string[] }|null}
|
|
28
|
-
*/
|
|
29
|
-
export function parseTestFilter(raw) {
|
|
30
|
-
if (raw === undefined || raw === null || raw === false) return null;
|
|
31
|
-
const text = String(raw);
|
|
32
|
-
return {
|
|
33
|
-
raw: text,
|
|
34
|
-
tokens: text.split(',').map((t) => t.trim().toLowerCase()).filter(Boolean),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Exact id or substring of the id, case-insensitive; a null filter matches everything. */
|
|
39
|
-
export function nodeMatchesFilter(node, filter) {
|
|
40
|
-
if (!filter) return true;
|
|
41
|
-
const id = String(node?.id ?? '').toLowerCase();
|
|
42
|
-
return filter.tokens.some((token) => id === token || id.includes(token));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Kept word for word from the singular resolver: readers already print it. */
|
|
46
|
-
const NO_SUITE_REASON = 'No testCommand configured and no known project file detected';
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @typedef {Object} TestNode
|
|
50
|
-
* @property {string} id
|
|
51
|
-
* @property {string|null} command - null only on a node already decided.
|
|
52
|
-
* @property {string} cwd - Relative to the project root.
|
|
53
|
-
* @property {string} runner - One of TEST_RUNNERS.
|
|
54
|
-
* @property {number|null} expectedCount - null is UNKNOWN, never 0.
|
|
55
|
-
* @property {number|null} timeoutMs - null means "derive the ceiling", never 0.
|
|
56
|
-
* @property {string[]} build - Test projects to compile first (dotnet only).
|
|
57
|
-
* @property {boolean} e2e
|
|
58
|
-
* @property {string|null} linuxImage - null defers to the run's image.
|
|
59
|
-
* @property {number} projectCount - Input to the derived timeout; 1 for a declared node.
|
|
60
|
-
* @property {'fail'|'skip'|null} status - Non-null means DO NOT EXECUTE.
|
|
61
|
-
* @property {string|null} reason
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
/** `npm test` can front any runner, so it infers `none`: a wrong guess would invent a number that fails gates. */
|
|
65
|
-
export function inferRunner(command) {
|
|
66
|
-
// `evals` is never inferred: an eval command is literally `dotnet test`, and
|
|
67
|
-
// reading a declared eval as plain dotnet would drop the cache pre-flight.
|
|
68
|
-
if (typeof command !== 'string' || !command.trim()) return 'none';
|
|
69
|
-
if (/\bdotnet\s+test\b/.test(command)) return 'dotnet';
|
|
70
|
-
if (/\bvitest\b/.test(command)) return 'vitest';
|
|
71
|
-
if (/\bplaywright\b/.test(command)) return 'playwright';
|
|
72
|
-
if (/\bjest\b/.test(command)) return 'jest';
|
|
73
|
-
if (/\bnode\b[^&|]*\s--test\b/.test(command) || /run-tests\.mjs\b/.test(command)) return 'node-test';
|
|
74
|
-
return 'none';
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function makeNode(partial) {
|
|
78
|
-
const runner = partial.runner ?? inferRunner(partial.command);
|
|
79
|
-
return {
|
|
80
|
-
id: partial.id,
|
|
81
|
-
command: partial.command ?? null,
|
|
82
|
-
cwd: partial.cwd ?? '.',
|
|
83
|
-
runner,
|
|
84
|
-
expectedCount: keepsBaseline(runner) ? partial.expectedCount ?? null : null,
|
|
85
|
-
timeoutMs: partial.timeoutMs ?? null,
|
|
86
|
-
parallel: partial.parallel ?? false,
|
|
87
|
-
build: partial.build ?? [],
|
|
88
|
-
e2e: partial.e2e ?? false,
|
|
89
|
-
linuxImage: partial.linuxImage ?? null,
|
|
90
|
-
projectCount: partial.projectCount ?? 1,
|
|
91
|
-
// null is "not an eval node", distinct from an empty block (already refused).
|
|
92
|
-
evals: partial.evals ?? null,
|
|
93
|
-
affected: partial.affected ?? null,
|
|
94
|
-
status: partial.status ?? null,
|
|
95
|
-
reason: partial.reason ?? null,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function invalidNode(id, problem, raw = {}) {
|
|
100
|
-
return makeNode({
|
|
101
|
-
id,
|
|
102
|
-
command: typeof raw.command === 'string' ? raw.command : null,
|
|
103
|
-
cwd: typeof raw.cwd === 'string' ? raw.cwd : '.',
|
|
104
|
-
status: 'fail',
|
|
105
|
-
reason: `invalid-test-node: ${id}: ${problem}`,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function isPlainObject(value) {
|
|
110
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function isNonNegativeInteger(value) {
|
|
114
|
-
return Number.isInteger(value) && value >= 0;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function firstProblem(raw, projectPath) {
|
|
118
|
-
if (!isPlainObject(raw)) return 'must be an object';
|
|
119
|
-
|
|
120
|
-
if (typeof raw.id !== 'string' || !TEST_NODE_ID_PATTERN.test(raw.id)) {
|
|
121
|
-
return `id must be a string matching ${TEST_NODE_ID_PATTERN.source}`;
|
|
122
|
-
}
|
|
123
|
-
if (typeof raw.command !== 'string' || !raw.command.trim()) {
|
|
124
|
-
return 'command must be a non-empty string';
|
|
125
|
-
}
|
|
126
|
-
if (raw.cwd !== undefined && (typeof raw.cwd !== 'string' || !raw.cwd.trim())) {
|
|
127
|
-
return 'cwd must be a non-empty string';
|
|
128
|
-
}
|
|
129
|
-
if (raw.runner !== undefined && !TEST_RUNNERS.includes(raw.runner)) {
|
|
130
|
-
return `runner must be one of ${TEST_RUNNERS.join(' | ')}`;
|
|
131
|
-
}
|
|
132
|
-
if (raw.affected !== undefined && (!isPlainObject(raw.affected) || typeof raw.affected.flag !== 'string' || !raw.affected.flag.trim())) {
|
|
133
|
-
return 'affected must be an object with a non-empty flag';
|
|
134
|
-
}
|
|
135
|
-
if (raw.expectedCount !== undefined && !isNonNegativeInteger(raw.expectedCount)) {
|
|
136
|
-
return 'expectedCount must be an integer >= 0';
|
|
137
|
-
}
|
|
138
|
-
if (raw.timeoutMs !== undefined && !(Number.isInteger(raw.timeoutMs) && raw.timeoutMs > 0)) {
|
|
139
|
-
return 'timeoutMs must be an integer > 0';
|
|
140
|
-
}
|
|
141
|
-
if (raw.parallel !== undefined && typeof raw.parallel !== 'boolean') {
|
|
142
|
-
return 'parallel must be a boolean';
|
|
143
|
-
}
|
|
144
|
-
if (raw.build !== undefined && (!Array.isArray(raw.build) || raw.build.some((b) => typeof b !== 'string'))) {
|
|
145
|
-
return 'build must be an array of strings';
|
|
146
|
-
}
|
|
147
|
-
// A declaration the verifier would silently ignore is refused, not dropped.
|
|
148
|
-
if (Array.isArray(raw.build) && raw.build.length > 0
|
|
149
|
-
&& (raw.runner ?? inferRunner(raw.command)) !== 'dotnet') {
|
|
150
|
-
return 'build applies only to runner "dotnet"';
|
|
151
|
-
}
|
|
152
|
-
if (raw.e2e !== undefined && typeof raw.e2e !== 'boolean') {
|
|
153
|
-
return 'e2e must be a boolean';
|
|
154
|
-
}
|
|
155
|
-
if (raw.linuxImage !== undefined && (typeof raw.linuxImage !== 'string' || !raw.linuxImage.trim())) {
|
|
156
|
-
return 'linuxImage must be a non-empty string';
|
|
157
|
-
}
|
|
158
|
-
if ((raw.runner ?? inferRunner(raw.command)) === EVAL_RUNNER) {
|
|
159
|
-
const problem = evalBlockProblem(raw, projectPath);
|
|
160
|
-
if (problem) return problem;
|
|
161
|
-
} else if (raw.evals !== undefined) {
|
|
162
|
-
return `evals applies only to runner "${EVAL_RUNNER}"`;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const cwd = typeof raw.cwd === 'string' ? raw.cwd.trim() : '.';
|
|
166
|
-
const root = resolve(projectPath ?? '.');
|
|
167
|
-
const abs = resolve(root, cwd);
|
|
168
|
-
if (!isInside(abs, root)) {
|
|
169
|
-
return `cwd "${cwd}" resolves outside the project root`;
|
|
170
|
-
}
|
|
171
|
-
if (projectPath && !existsSync(abs)) {
|
|
172
|
-
// Named failure, never a skip: a skip would hide a wrong cwd behind a green gate.
|
|
173
|
-
return `cwd "${cwd}" does not exist`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Fail-CLOSED, unlike the repo's other config readers: a typo that falls through
|
|
181
|
-
* to the fallback resolver gives a green gate over a suite that never ran.
|
|
182
|
-
* A bad entry becomes a `status: 'fail'` node, never a node that disappears.
|
|
183
|
-
* @returns {TestNode[]} One node per declared entry, in declaration order
|
|
184
|
-
*/
|
|
185
|
-
export function validateTestNodes(config, projectPath = null) {
|
|
186
|
-
const raw = config?.project?.tests;
|
|
187
|
-
|
|
188
|
-
if (!Array.isArray(raw)) {
|
|
189
|
-
return [invalidNode('project.tests', 'must be an array of test nodes')];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Duplicate ids fail on both sides: picking a winner would silence a declared suite.
|
|
193
|
-
const seen = new Map();
|
|
194
|
-
for (const entry of raw) {
|
|
195
|
-
if (isPlainObject(entry) && typeof entry.id === 'string') {
|
|
196
|
-
seen.set(entry.id, (seen.get(entry.id) ?? 0) + 1);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return raw.map((entry, index) => {
|
|
201
|
-
const id = isPlainObject(entry) && typeof entry.id === 'string' && entry.id
|
|
202
|
-
? entry.id
|
|
203
|
-
: `tests[${index}]`;
|
|
204
|
-
|
|
205
|
-
const problem = firstProblem(entry, projectPath);
|
|
206
|
-
if (problem) return invalidNode(id, problem, isPlainObject(entry) ? entry : {});
|
|
207
|
-
|
|
208
|
-
if (seen.get(entry.id) > 1) {
|
|
209
|
-
return invalidNode(id, `duplicate id "${entry.id}" — ids must be unique within tests[]`, entry);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return makeNode({
|
|
213
|
-
id: entry.id,
|
|
214
|
-
command: entry.command,
|
|
215
|
-
cwd: typeof entry.cwd === 'string' ? entry.cwd.trim() : '.',
|
|
216
|
-
runner: entry.runner ?? inferRunner(entry.command),
|
|
217
|
-
expectedCount: entry.expectedCount ?? null,
|
|
218
|
-
timeoutMs: entry.timeoutMs ?? null,
|
|
219
|
-
parallel: entry.parallel ?? false,
|
|
220
|
-
build: entry.build ?? [],
|
|
221
|
-
e2e: entry.e2e ?? false,
|
|
222
|
-
linuxImage: entry.linuxImage ?? null,
|
|
223
|
-
evals: entry.evals ?? null,
|
|
224
|
-
affected: entry.affected ?? null,
|
|
225
|
-
projectCount: 1,
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function slugifyForId(text) {
|
|
231
|
-
return text
|
|
232
|
-
.toLowerCase()
|
|
233
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
234
|
-
.replace(/^-+|-+$/g, '');
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* A GUESS from `package.json` (vitest/jest in deps), never a declaration — so it
|
|
239
|
-
* is fail-open: an unreadable `package.json` is skipped, never a `fail` node.
|
|
240
|
-
* @returns {Array<{ id: string, cwd: string, runner: 'vitest'|'jest', command: string }>}
|
|
241
|
-
*/
|
|
242
|
-
export function discoverFrontendPackages(projectPath, config) {
|
|
243
|
-
const root = resolve(projectPath);
|
|
244
|
-
const candidates = [...PACKAGE_LOCATIONS];
|
|
245
|
-
|
|
246
|
-
const frontendPath = config?.project?.frontendPath;
|
|
247
|
-
if (typeof frontendPath === 'string' && frontendPath.trim()) {
|
|
248
|
-
const abs = resolve(root, frontendPath.trim());
|
|
249
|
-
if (isInside(abs, root)) candidates.push(frontendPath.trim());
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const seenDirs = new Set();
|
|
253
|
-
const seenIds = new Set();
|
|
254
|
-
const found = [];
|
|
255
|
-
|
|
256
|
-
for (const loc of candidates) {
|
|
257
|
-
const dirAbs = resolve(root, loc);
|
|
258
|
-
if (seenDirs.has(dirAbs)) continue;
|
|
259
|
-
seenDirs.add(dirAbs);
|
|
260
|
-
|
|
261
|
-
const pkgPath = join(dirAbs, 'package.json');
|
|
262
|
-
if (!existsSync(pkgPath)) continue;
|
|
263
|
-
|
|
264
|
-
let pkg;
|
|
265
|
-
try {
|
|
266
|
-
pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
267
|
-
} catch {
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const deps = { ...(pkg?.dependencies ?? {}), ...(pkg?.devDependencies ?? {}) };
|
|
272
|
-
let runner = null;
|
|
273
|
-
let command = null;
|
|
274
|
-
if (deps.vitest) {
|
|
275
|
-
runner = 'vitest';
|
|
276
|
-
command = 'npx vitest run';
|
|
277
|
-
} else if (deps.jest) {
|
|
278
|
-
runner = 'jest';
|
|
279
|
-
command = 'npx jest --ci';
|
|
280
|
-
}
|
|
281
|
-
if (!runner) continue;
|
|
282
|
-
|
|
283
|
-
const cwd = dirAbs === root ? '.' : relative(root, dirAbs).split(sep).join('/');
|
|
284
|
-
const baseId = cwd === '.' ? runner : `${runner}-${slugifyForId(cwd)}`;
|
|
285
|
-
let id = baseId;
|
|
286
|
-
let n = 2;
|
|
287
|
-
while (seenIds.has(id)) {
|
|
288
|
-
id = `${baseId}-${n}`;
|
|
289
|
-
n += 1;
|
|
290
|
-
}
|
|
291
|
-
seenIds.add(id);
|
|
292
|
-
|
|
293
|
-
found.push({ id, cwd, runner, command });
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return found;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Precedence: `project.tests[]` → `project.testCommand` → `resolveTestPlan()`'s
|
|
301
|
-
* fallback (called, never re-implemented: it owns the order and the worktree
|
|
302
|
-
* exclusion). Never empty: "nothing to run" is one node decided as `skip`.
|
|
303
|
-
* @returns {{ nodes: TestNode[], source: string }}
|
|
304
|
-
*/
|
|
305
|
-
export function resolveTestNodes(projectPath = '.') {
|
|
306
|
-
const config = readMorphConfig(projectPath);
|
|
307
|
-
|
|
308
|
-
// `tests` in ANY shape is a declaration: falling back from a typo hides a suite.
|
|
309
|
-
if (config?.project?.tests !== undefined) {
|
|
310
|
-
const nodes = validateTestNodes(config, projectPath);
|
|
311
|
-
if (Array.isArray(config.project.tests) && config.project.tests.length === 0) {
|
|
312
|
-
// `[]` declares "no suites"; an absent key means "guess for me".
|
|
313
|
-
return {
|
|
314
|
-
nodes: [makeNode({ id: 'none', status: 'skip', reason: 'no test nodes declared' })],
|
|
315
|
-
source: 'config-tests',
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
return { nodes, source: 'config-tests' };
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const plan = resolveTestPlan(projectPath);
|
|
322
|
-
|
|
323
|
-
const nodes = [
|
|
324
|
-
plan.command
|
|
325
|
-
? makeNode({ id: FALLBACK_NODE_ID, command: plan.command, cwd: '.', projectCount: plan.projectCount })
|
|
326
|
-
: makeNode({ id: FALLBACK_NODE_ID, status: 'skip', reason: NO_SUITE_REASON }),
|
|
327
|
-
];
|
|
328
|
-
|
|
329
|
-
// Discovered frontend suites go BESIDE the fallback node, never beside a
|
|
330
|
-
// declaration (`plan.source === 'config'` is `project.testCommand`).
|
|
331
|
-
if (plan.source !== 'config') {
|
|
332
|
-
const discovered = discoverFrontendPackages(projectPath, config)
|
|
333
|
-
// The root package is already run by the fallback's `npm test`.
|
|
334
|
-
.filter((pkg) => !(pkg.cwd === '.' && plan.source === 'npm'))
|
|
335
|
-
.map((pkg) => makeNode({ id: pkg.id, command: pkg.command, cwd: pkg.cwd, runner: pkg.runner }));
|
|
336
|
-
nodes.push(...discovered);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
return { nodes, source: plan.source };
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
export function morphConfigPath(projectPath = '.') {
|
|
343
|
-
return join(projectPath, CONFIG_FILE_NAME);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* The only writer of `expectedCount`: a baseline is measured by a green run, never typed.
|
|
348
|
-
* Refuses a non-integer count (null is UNKNOWN, never 0), an undeclared id, or a
|
|
349
|
-
* declared node with no measurement. Every other config key survives.
|
|
350
|
-
* @param {Array<{id: string, count: number|null}>} measurements
|
|
351
|
-
* @returns {{ recorded: boolean, reason: string|null, updates: Array<{id: string, from: number|null, to: number}>, removed: string[], path: string }}
|
|
352
|
-
*/
|
|
353
|
-
export function recordTestBaselines(projectPath, measurements) {
|
|
354
|
-
const path = morphConfigPath(projectPath);
|
|
355
|
-
const refuse = (reason) => ({ recorded: false, reason, updates: [], removed: [], path });
|
|
356
|
-
|
|
357
|
-
if (!existsSync(path)) return refuse('não existe .morph/config/config.json — não há onde gravar');
|
|
358
|
-
|
|
359
|
-
let config;
|
|
360
|
-
try {
|
|
361
|
-
config = JSON.parse(readFileSync(path, 'utf8'));
|
|
362
|
-
} catch (err) {
|
|
363
|
-
return refuse(`config.json ilegível (${err.message})`);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
const declared = config?.project?.tests;
|
|
367
|
-
if (!Array.isArray(declared)) {
|
|
368
|
-
return refuse('config.json não declara project.tests[] — não há entrada onde gravar a baseline');
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
const runnerOf = new Map(declared.filter(isPlainObject).map((e) => [e.id, e.runner ?? inferRunner(e.command)]));
|
|
372
|
-
const unreadable = measurements
|
|
373
|
-
.filter((m) => keepsBaseline(runnerOf.get(m.id)) && !Number.isInteger(m.count))
|
|
374
|
-
.map((m) => m.id);
|
|
375
|
-
if (unreadable.length > 0) {
|
|
376
|
-
return refuse(`contagem desconhecida em: ${unreadable.join(', ')} — desconhecido nunca vira 0`);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
const byId = new Map(measurements.map((m) => [m.id, m.count]));
|
|
380
|
-
const undeclared = [...byId.keys()].filter(
|
|
381
|
-
(id) => !declared.some((entry) => entry && entry.id === id)
|
|
382
|
-
);
|
|
383
|
-
if (undeclared.length > 0) {
|
|
384
|
-
return refuse(`nó medido não declarado em project.tests[]: ${undeclared.join(', ')}`);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const unmeasured = declared
|
|
388
|
-
.map((entry) => entry?.id)
|
|
389
|
-
.filter((id) => typeof id === 'string' && !byId.has(id));
|
|
390
|
-
if (unmeasured.length > 0) {
|
|
391
|
-
return refuse(`nó declarado sem medição: ${unmeasured.join(', ')} — baseline parcial não é baseline`);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const updates = [];
|
|
395
|
-
const removed = [];
|
|
396
|
-
for (const entry of declared) {
|
|
397
|
-
if (!entry || !byId.has(entry.id)) continue;
|
|
398
|
-
if (!keepsBaseline(runnerOf.get(entry.id))) {
|
|
399
|
-
if ('expectedCount' in entry) removed.push(entry.id);
|
|
400
|
-
delete entry.expectedCount;
|
|
401
|
-
continue;
|
|
402
|
-
}
|
|
403
|
-
const to = byId.get(entry.id);
|
|
404
|
-
updates.push({
|
|
405
|
-
id: entry.id,
|
|
406
|
-
from: Number.isInteger(entry.expectedCount) ? entry.expectedCount : null,
|
|
407
|
-
to,
|
|
408
|
-
});
|
|
409
|
-
entry.expectedCount = to;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
atomicWriteJson(path, config);
|
|
413
|
-
return { recorded: true, reason: null, updates, removed, path };
|
|
414
|
-
}
|