@skathio/somi 4.1.1 → 5.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-plugin/icon.png +0 -0
- package/.claude-plugin/marketplace.json +8 -3
- package/.claude-plugin/plugin.json +9 -10
- package/.copilot-extension/extension.json +32 -40
- package/.copilot-extension/marketplace.json +8 -3
- package/README.md +83 -228
- package/VERSION +1 -1
- package/agents/somi-reviewer.md +21 -40
- package/agents/somi-security-reviewer.md +16 -90
- package/agents/somi-worker-high.md +11 -0
- package/agents/somi-worker-low.md +11 -0
- package/agents/somi-worker-medium.md +11 -0
- package/agents/somi.md +8 -75
- package/commands/somi-config.md +5 -14
- package/commands/somi-deliver.md +11 -0
- package/commands/somi-quality.md +10 -0
- package/commands/somi-review.md +10 -0
- package/commands/somi-status.md +11 -0
- package/commands/somi.md +10 -0
- package/hooks/hooks.json +28 -23
- package/hooks/lib/common.mjs +45 -34
- package/hooks/pre-tool/apply-tier.mjs +31 -0
- package/hooks/pre-tool/block-dangerous-bash.mjs +15 -0
- package/hooks/pre-tool/gate-dep-install.mjs +2 -2
- package/hooks/pre-tool/guard-protected-paths.mjs +9 -16
- package/hooks/pre-tool/guard-tier-config.mjs +17 -0
- package/hooks/pre-tool/reviewers-read-only.mjs +11 -0
- package/hooks/session-start/inject-digest.mjs +51 -0
- package/hooks/stop/review-due.mjs +40 -0
- package/hooks/user-prompt/capture-prompt.mjs +17 -0
- package/library/lenses/architecture.md +1 -0
- package/library/lenses/test-strategy.md +1 -0
- package/library/roles/accessibility.md +1 -0
- package/library/roles/answer.md +1 -0
- package/library/roles/atlas.md +1 -0
- package/library/roles/build.md +1 -0
- package/library/roles/debug.md +6 -0
- package/library/roles/design.md +1 -0
- package/library/roles/discover.md +1 -0
- package/library/roles/incident.md +1 -0
- package/library/roles/migrate.md +1 -0
- package/library/roles/perf.md +1 -0
- package/library/roles/plan.md +1 -0
- package/library/roles/refactor.md +1 -0
- package/library/roles/review.md +1 -0
- package/library/roles/security-review.md +1 -0
- package/library/roles/upgrade.md +1 -0
- package/library/skills/accessibility.md +16 -0
- package/library/skills/ci-infra-gotchas.md +12 -0
- package/library/skills/perf-method.md +10 -0
- package/library/skills/secure-coding.md +18 -0
- package/library/skills/testing-checklist.md +16 -0
- package/library/skills/threat-modeling.md +10 -0
- package/package.json +12 -17
- package/profiles/claude.json +21 -0
- package/profiles/copilot.json +5 -0
- package/rules/digest.md +40 -0
- package/scripts/check-links.mjs +65 -76
- package/scripts/lib/advisor.mjs +207 -0
- package/scripts/lib/check.mjs +165 -0
- package/scripts/lib/copilot-workflow.mjs +41 -0
- package/scripts/lib/doctor.mjs +91 -0
- package/scripts/lib/gates.mjs +69 -0
- package/scripts/lib/git-tree.mjs +201 -0
- package/scripts/lib/init.mjs +23 -0
- package/scripts/lib/ledger.mjs +38 -0
- package/scripts/lib/mcp-project-root.mjs +63 -67
- package/scripts/lib/migrate.mjs +73 -0
- package/scripts/lib/path-facts.mjs +2 -2
- package/scripts/lib/path-safety.mjs +6 -134
- package/scripts/lib/plan.mjs +69 -0
- package/scripts/lib/policy.mjs +103 -0
- package/scripts/lib/pr.mjs +28 -0
- package/scripts/lib/prompt.mjs +72 -0
- package/scripts/lib/quality/clones.mjs +76 -0
- package/scripts/lib/quality/css.mjs +43 -0
- package/scripts/lib/quality/gate.mjs +230 -0
- package/scripts/lib/quality/limits.mjs +73 -0
- package/scripts/lib/quality/metrics.mjs +159 -0
- package/scripts/lib/quality/parse.mjs +73 -0
- package/scripts/lib/quality/repo.mjs +69 -0
- package/scripts/lib/quality/run.mjs +38 -0
- package/scripts/lib/reviews.mjs +132 -0
- package/scripts/lib/routes.mjs +108 -0
- package/scripts/lib/setup.mjs +34 -0
- package/scripts/lib/shards.mjs +166 -0
- package/scripts/lib/signals.mjs +110 -0
- package/scripts/lib/state.mjs +42 -0
- package/scripts/lib/tiers.mjs +42 -0
- package/scripts/lib/update-notice.mjs +48 -0
- package/scripts/lib/views.mjs +62 -0
- package/scripts/lib/workflows.mjs +56 -0
- package/scripts/somi-mcp.mjs +181 -323
- package/scripts/somi.mjs +208 -0
- package/scripts/vendor/tree-sitter/LICENSE.vscode-tree-sitter-wasm +21 -0
- package/scripts/vendor/tree-sitter/LICENSE.web-tree-sitter +21 -0
- package/scripts/vendor/tree-sitter/cgmanifest.vscode-tree-sitter-wasm.json +16 -0
- package/scripts/vendor/tree-sitter/manifest.json +59 -0
- package/scripts/vendor/tree-sitter/package.json +3 -0
- package/scripts/vendor/tree-sitter/tree-sitter-css.wasm +0 -0
- package/scripts/vendor/tree-sitter/tree-sitter-javascript.wasm +0 -0
- package/scripts/vendor/tree-sitter/tree-sitter-tsx.wasm +0 -0
- package/scripts/vendor/tree-sitter/tree-sitter-typescript.wasm +0 -0
- package/scripts/vendor/tree-sitter/web-tree-sitter.js +4081 -0
- package/scripts/vendor/tree-sitter/web-tree-sitter.wasm +0 -0
- package/skills/somi-expertise/SKILL.md +6 -0
- package/workflows/deliver-stages.js +81 -0
- package/.claude/settings.json +0 -131
- package/agents/somi-architecture-reviewer.md +0 -101
- package/agents/somi-atlas.md +0 -100
- package/agents/somi-coder.md +0 -60
- package/agents/somi-designer.md +0 -36
- package/agents/somi-discovery-analyst.md +0 -57
- package/agents/somi-flow.md +0 -47
- package/agents/somi-general.md +0 -36
- package/agents/somi-impact.md +0 -95
- package/agents/somi-incident.md +0 -94
- package/agents/somi-plan-reviewer.md +0 -68
- package/agents/somi-planner.md +0 -57
- package/agents/somi-pr.md +0 -99
- package/agents/somi-refactor-designer.md +0 -81
- package/agents/somi-refactorer.md +0 -99
- package/agents/somi-sdlc-reviewer.md +0 -67
- package/agents/somi-test-strategist.md +0 -87
- package/commands/adopt.md +0 -14
- package/commands/architecture-review.md +0 -19
- package/commands/atlas.md +0 -19
- package/commands/code-loop.md +0 -19
- package/commands/code-parallel.md +0 -19
- package/commands/code.md +0 -19
- package/commands/debug.md +0 -19
- package/commands/design.md +0 -19
- package/commands/discover.md +0 -19
- package/commands/impact.md +0 -19
- package/commands/incident.md +0 -19
- package/commands/plan-loop.md +0 -19
- package/commands/plan.md +0 -19
- package/commands/pr.md +0 -19
- package/commands/refactor-design.md +0 -19
- package/commands/refactor.md +0 -19
- package/commands/release-readiness.md +0 -19
- package/commands/review-panel.md +0 -19
- package/commands/review.md +0 -19
- package/commands/security-review.md +0 -19
- package/commands/ship-loop.md +0 -19
- package/commands/ship.md +0 -19
- package/commands/test-strategy.md +0 -19
- package/commands/upgrade.md +0 -19
- package/examples/README.md +0 -19
- package/examples/code-review-example.md +0 -88
- package/examples/discovery-example.md +0 -200
- package/examples/feature-plan-example.md +0 -377
- package/examples/full-pipeline-example.md +0 -188
- package/examples/sample-consumer/.claude/settings.json +0 -29
- package/examples/sample-consumer/CLAUDE.md +0 -78
- package/examples/sample-consumer/README.md +0 -102
- package/hooks/post-tool/lint-changed-files.mjs +0 -209
- package/hooks/pre-tool/guard-cost-lowering.mjs +0 -192
- package/hooks/session-start/detect-repo-instructions.mjs +0 -287
- package/hooks/session-start/ensure-default-config.mjs +0 -113
- package/hooks/user-prompt-submit/inject-workflow-context.mjs +0 -580
- package/rules/00-priorities.md +0 -48
- package/rules/10-solid.md +0 -87
- package/rules/20-clean-code.md +0 -62
- package/rules/30-security-owasp.md +0 -83
- package/rules/40-engineering-practices.md +0 -65
- package/rules/50-collaboration.md +0 -114
- package/rules/99-overrides.md +0 -52
- package/rules/CLAUDE.md +0 -200
- package/scripts/check-session-artefacts.mjs +0 -149
- package/scripts/check-size-budget.mjs +0 -137
- package/scripts/generate-digest.mjs +0 -176
- package/scripts/lib/agent-info.mjs +0 -85
- package/scripts/lib/agent-registry.mjs +0 -92
- package/scripts/lib/cost-ceiling.mjs +0 -328
- package/scripts/lib/cost-config-edit.mjs +0 -102
- package/scripts/lib/cost-config.mjs +0 -64
- package/scripts/lib/cost-defaults.mjs +0 -53
- package/scripts/lib/cost-lowering.mjs +0 -89
- package/scripts/lib/cost-model.mjs +0 -110
- package/scripts/lib/dispatch-resolver.mjs +0 -243
- package/scripts/lib/escalation-facts.mjs +0 -146
- package/scripts/lib/escalation.mjs +0 -129
- package/scripts/lib/findings-ledger.mjs +0 -241
- package/scripts/lib/install-text.mjs +0 -97
- package/scripts/lib/loop-caps.mjs +0 -140
- package/scripts/lib/loop-diff.mjs +0 -38
- package/scripts/lib/loop-dispatch.mjs +0 -19
- package/scripts/lib/loop-engine.mjs +0 -227
- package/scripts/lib/loop-escalate.mjs +0 -49
- package/scripts/lib/loop-exit.mjs +0 -47
- package/scripts/lib/loop-notes-compact.mjs +0 -72
- package/scripts/lib/loop-notes.mjs +0 -282
- package/scripts/lib/loop-review.mjs +0 -395
- package/scripts/lib/loop-state.mjs +0 -44
- package/scripts/lib/loop-step-close.mjs +0 -75
- package/scripts/lib/loop-step-kit.mjs +0 -179
- package/scripts/lib/loop-step-review.mjs +0 -140
- package/scripts/lib/loop-step-tool.mjs +0 -89
- package/scripts/lib/loop-step.mjs +0 -303
- package/scripts/lib/run-budget.mjs +0 -28
- package/scripts/lib/run-card.mjs +0 -73
- package/scripts/lib/size-tier.mjs +0 -184
- package/scripts/lib/tier-record.mjs +0 -82
- package/scripts/size-budget-overrides.json +0 -58
- package/scripts/somi-card.mjs +0 -39
- package/scripts/somi-check.mjs +0 -237
- package/scripts/somi-config.mjs +0 -421
- package/scripts/somi-dispatch.mjs +0 -141
- package/scripts/somi-findings.mjs +0 -100
- package/scripts/somi-loop.mjs +0 -139
- package/scripts/somi-tier.mjs +0 -393
- package/scripts/validate.sh +0 -653
- package/skills/api-design/SKILL.md +0 -147
- package/skills/clean-code/SKILL.md +0 -142
- package/skills/flow-adopt/SKILL.md +0 -92
- package/skills/flow-architecture-review/SKILL.md +0 -94
- package/skills/flow-atlas/SKILL.md +0 -34
- package/skills/flow-code/SKILL.md +0 -167
- package/skills/flow-code-loop/SKILL.md +0 -263
- package/skills/flow-code-parallel/SKILL.md +0 -160
- package/skills/flow-debug/SKILL.md +0 -141
- package/skills/flow-design/SKILL.md +0 -170
- package/skills/flow-discover/SKILL.md +0 -204
- package/skills/flow-impact/SKILL.md +0 -35
- package/skills/flow-incident/SKILL.md +0 -49
- package/skills/flow-plan/SKILL.md +0 -254
- package/skills/flow-plan-loop/SKILL.md +0 -254
- package/skills/flow-pr/SKILL.md +0 -34
- package/skills/flow-refactor/SKILL.md +0 -58
- package/skills/flow-refactor-design/SKILL.md +0 -97
- package/skills/flow-release-readiness/SKILL.md +0 -82
- package/skills/flow-review/SKILL.md +0 -193
- package/skills/flow-review-panel/SKILL.md +0 -154
- package/skills/flow-security-review/SKILL.md +0 -83
- package/skills/flow-ship/SKILL.md +0 -125
- package/skills/flow-ship-loop/SKILL.md +0 -274
- package/skills/flow-somi-config/SKILL.md +0 -142
- package/skills/flow-status/SKILL.md +0 -43
- package/skills/flow-test-strategy/SKILL.md +0 -83
- package/skills/flow-upgrade/SKILL.md +0 -82
- package/skills/market-research/SKILL.md +0 -125
- package/skills/observability/SKILL.md +0 -133
- package/skills/owasp-defense/SKILL.md +0 -141
- package/skills/plan-review/SKILL.md +0 -83
- package/skills/reasoning-craft/SKILL.md +0 -213
- package/skills/requirements-engineering/SKILL.md +0 -137
- package/skills/role-coder/SKILL.md +0 -247
- package/skills/role-designer/SKILL.md +0 -172
- package/skills/role-discovery-analyst/SKILL.md +0 -288
- package/skills/role-planner/SKILL.md +0 -353
- package/skills/role-reviewer/SKILL.md +0 -218
- package/skills/rules/SKILL.md +0 -47
- package/skills/sdlc-process/SKILL.md +0 -74
- package/skills/solid-principles/SKILL.md +0 -143
- package/skills/somi-checkpoint/SKILL.md +0 -95
- package/skills/somi-dispatch/SKILL.md +0 -259
- package/skills/somi-routing/SKILL.md +0 -158
- package/skills/testing-playbook/SKILL.md +0 -133
- package/skills/threat-modeling/SKILL.md +0 -117
- package/templates/ADR.md.tmpl +0 -73
- package/templates/ATLAS.md.tmpl +0 -75
- package/templates/BRD.md.tmpl +0 -68
- package/templates/BRIEF.md.tmpl +0 -119
- package/templates/CONTEXT.md.tmpl +0 -74
- package/templates/DECISIONS.md.tmpl +0 -105
- package/templates/DESIGN.md.tmpl +0 -83
- package/templates/DIARY.md.tmpl +0 -70
- package/templates/DOD.md.tmpl +0 -90
- package/templates/FRD.md.tmpl +0 -64
- package/templates/PHASE.md.tmpl +0 -80
- package/templates/PROGRESS.md.tmpl +0 -63
- package/templates/RCA.md.tmpl +0 -53
- package/templates/RD-README.md.tmpl +0 -70
- package/templates/RESEARCH.md.tmpl +0 -96
- package/templates/REVIEW.md.tmpl +0 -82
- package/templates/SDD.md.tmpl +0 -82
- package/templates/SOMI-README.md.tmpl +0 -83
- package/templates/SPEC.md.tmpl +0 -123
- package/templates/SRS.md.tmpl +0 -85
- package/templates/TDD.md.tmpl +0 -77
- package/tests/hooks/cases/audit-log.json +0 -21
- package/tests/hooks/cases/block-dangerous-bash.json +0 -166
- package/tests/hooks/cases/block-secret-writes.json +0 -140
- package/tests/hooks/cases/detect-repo-instructions.json +0 -105
- package/tests/hooks/cases/gate-dep-install.json +0 -42
- package/tests/hooks/cases/guard-protected-paths.json +0 -222
- package/tests/hooks/cases/inject-workflow-context.json +0 -239
- package/tests/hooks/cases/lint-changed-files.json +0 -120
- package/tests/hooks/run.sh +0 -392
- package/tests/scripts/agent-model-frontmatter.sh +0 -38
- package/tests/scripts/agent-names.sh +0 -77
- package/tests/scripts/check-frontmatter.sh +0 -37
- package/tests/scripts/check-links.sh +0 -105
- package/tests/scripts/check-session-artefacts.sh +0 -60
- package/tests/scripts/check-size-budget.sh +0 -71
- package/tests/scripts/checkpoint-gate.sh +0 -131
- package/tests/scripts/convergence-runner.sh +0 -1514
- package/tests/scripts/cost-ceiling.sh +0 -255
- package/tests/scripts/cost-defaults.sh +0 -130
- package/tests/scripts/cost-hardcap.sh +0 -338
- package/tests/scripts/cost-lowering.sh +0 -261
- package/tests/scripts/cost-model.sh +0 -196
- package/tests/scripts/dispatch-guard.sh +0 -108
- package/tests/scripts/dispatch-line-gate.sh +0 -61
- package/tests/scripts/dispatch-reference-gate.sh +0 -173
- package/tests/scripts/ensure-default-config.sh +0 -162
- package/tests/scripts/escalation.sh +0 -409
- package/tests/scripts/eval-runner.sh +0 -3692
- package/tests/scripts/evals-packaging.sh +0 -224
- package/tests/scripts/fact-sheet.sh +0 -296
- package/tests/scripts/fixtures/legacy-shard-no-schema.json +0 -50
- package/tests/scripts/fixtures/mock-stdin-read-throw.cjs +0 -18
- package/tests/scripts/fixtures/size-tier-cases.json +0 -87
- package/tests/scripts/generate-digest.sh +0 -180
- package/tests/scripts/global-config.sh +0 -167
- package/tests/scripts/goldens/loop-state-breach.json +0 -1
- package/tests/scripts/goldens/loop-state-done.json +0 -1
- package/tests/scripts/goldens/somi-findings.json +0 -336
- package/tests/scripts/goldens/somi-loop.json +0 -168
- package/tests/scripts/lib/adr-shape.mjs +0 -41
- package/tests/scripts/lib/agent-registry-tests.mjs +0 -95
- package/tests/scripts/lib/brief-only-guard.mjs +0 -27
- package/tests/scripts/lib/checkpoint-gate.mjs +0 -91
- package/tests/scripts/lib/digest-marker-coupling.mjs +0 -52
- package/tests/scripts/lib/dispatch-reference-gate.mjs +0 -121
- package/tests/scripts/lib/escalation-facts-tests.mjs +0 -140
- package/tests/scripts/lib/escalation-tests.mjs +0 -154
- package/tests/scripts/lib/findings-ledger-tests.mjs +0 -118
- package/tests/scripts/lib/loop-engine-tests.mjs +0 -287
- package/tests/scripts/lib/loop-escalate-tests.mjs +0 -356
- package/tests/scripts/lib/loop-flow-gate.mjs +0 -173
- package/tests/scripts/lib/loop-notes-tests.mjs +0 -384
- package/tests/scripts/lib/loop-step-cli-tests.mjs +0 -156
- package/tests/scripts/lib/loop-step-close-tests.mjs +0 -351
- package/tests/scripts/lib/loop-step-lenient-tests.mjs +0 -114
- package/tests/scripts/lib/loop-step-state-tests.mjs +0 -127
- package/tests/scripts/lib/loop-step-tests.mjs +0 -499
- package/tests/scripts/lib/loop-step-unwritten-tests.mjs +0 -55
- package/tests/scripts/lib/multipass-dependence.mjs +0 -192
- package/tests/scripts/lib/multipass-source-identity.mjs +0 -243
- package/tests/scripts/lib/path-facts-tests.mjs +0 -198
- package/tests/scripts/lib/path-safety-tests.mjs +0 -201
- package/tests/scripts/lib/reference-pair.mjs +0 -61
- package/tests/scripts/lib/retirement-gate.mjs +0 -172
- package/tests/scripts/lib/run-suites.mjs +0 -139
- package/tests/scripts/lib/shell-embedded-js.mjs +0 -47
- package/tests/scripts/lib/ship-loop-sizing-guard.mjs +0 -52
- package/tests/scripts/lib/site-roadmap-gate.mjs +0 -64
- package/tests/scripts/lib/size-tier-drift.mjs +0 -74
- package/tests/scripts/lib/sizing-score-tests.mjs +0 -210
- package/tests/scripts/lib/sizing-set-tests.mjs +0 -131
- package/tests/scripts/lib/somi-mcp-client.mjs +0 -102
- package/tests/scripts/lib/somi-mcp-config-tests.mjs +0 -92
- package/tests/scripts/lib/somi-mcp-loop-tests.mjs +0 -226
- package/tests/scripts/lib/somi-mcp-tests.mjs +0 -491
- package/tests/scripts/lib/somi-mcp-tier-tests.mjs +0 -64
- package/tests/scripts/lib/somi-mcp-tool-schema.mjs +0 -38
- package/tests/scripts/loop-engine.sh +0 -22
- package/tests/scripts/loop-flow-gate.sh +0 -11
- package/tests/scripts/retirement-gate.sh +0 -306
- package/tests/scripts/review-panel-seats.sh +0 -32
- package/tests/scripts/run-card.sh +0 -57
- package/tests/scripts/run-suites.sh +0 -74
- package/tests/scripts/run.sh +0 -689
- package/tests/scripts/site-roadmap-gate.sh +0 -76
- package/tests/scripts/size-tier.sh +0 -562
- package/tests/scripts/somi-agent-dispatch-contract.sh +0 -224
- package/tests/scripts/somi-config.sh +0 -286
- package/tests/scripts/somi-dispatch.sh +0 -465
- package/tests/scripts/somi-mcp.sh +0 -15
- package/tests/scripts/suite-plan.json +0 -20
package/tests/scripts/run.sh
DELETED
|
@@ -1,689 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# End-to-end tests for scripts/somi-loop.sh and scripts/somi-findings.sh.
|
|
3
|
-
#
|
|
4
|
-
# Exercises the deterministic loop core in a throwaway git repo: cap resolution
|
|
5
|
-
# (flag > env > config > default), pass counting, weighted diff measurement
|
|
6
|
-
# (out-of-scope double-counting, .somi/.claude exclusion), resume-after-death,
|
|
7
|
-
# and the findings ledger (identity, consecutive-pass breaker, cross-run
|
|
8
|
-
# recurrence, resolve lifecycle).
|
|
9
|
-
#
|
|
10
|
-
# Wired into scripts/validate.sh (npm test) — CI fails when the loop arithmetic
|
|
11
|
-
# or the breaker semantics regress.
|
|
12
|
-
|
|
13
|
-
set -euo pipefail
|
|
14
|
-
|
|
15
|
-
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
16
|
-
LOOP="$ROOT/scripts/somi-loop.mjs"
|
|
17
|
-
FINDINGS="$ROOT/scripts/somi-findings.mjs"
|
|
18
|
-
|
|
19
|
-
TMP="$(mktemp -d)"
|
|
20
|
-
trap 'rm -rf "$TMP"' EXIT
|
|
21
|
-
|
|
22
|
-
failures=0
|
|
23
|
-
total=0
|
|
24
|
-
check() { # $1 = name, $2 = 0/1 pass
|
|
25
|
-
total=$((total + 1))
|
|
26
|
-
if [[ "$2" != "0" ]]; then
|
|
27
|
-
echo "FAIL: $1" >&2
|
|
28
|
-
failures=$((failures + 1))
|
|
29
|
-
fi
|
|
30
|
-
}
|
|
31
|
-
expect_exit() { # $1 = name, $2 = expected code, then the command …
|
|
32
|
-
local name="$1" want="$2" got=0; shift 2
|
|
33
|
-
"$@" >/dev/null 2>&1 || got=$?
|
|
34
|
-
if [[ "$got" != "$want" ]]; then
|
|
35
|
-
echo "FAIL: $name — expected exit $want, got $got" >&2
|
|
36
|
-
failures=$((failures + 1))
|
|
37
|
-
fi
|
|
38
|
-
total=$((total + 1))
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
# --- throwaway project repo ---------------------------------------------------
|
|
42
|
-
REPO="$TMP/repo"
|
|
43
|
-
mkdir -p "$REPO/src" "$REPO/.somi"
|
|
44
|
-
cd "$REPO"
|
|
45
|
-
git init -q -b main
|
|
46
|
-
git config user.email t@t && git config user.name t
|
|
47
|
-
printf 'one\n' > src/a.txt
|
|
48
|
-
printf 'one\n' > src/b.txt
|
|
49
|
-
git add -A && git commit -qm init
|
|
50
|
-
|
|
51
|
-
export CLAUDE_PROJECT_DIR="$REPO"
|
|
52
|
-
unset SOMI_CODE_LOOP_MAX_PASSES SOMI_CODE_LOOP_DIFF_CAP SOMI_CODE_LOOP_SEVERITY_FLOOR 2>/dev/null || true
|
|
53
|
-
|
|
54
|
-
# --- somi-loop: init + cap precedence ------------------------------------------
|
|
55
|
-
printf '{"code_loop": {"max_passes": 2, "diff_cap_lines": 10}}\n' > .somi/config.json
|
|
56
|
-
out="$(node "$LOOP" init --slug demo --loop code --iteration 1.1 --files "src/a.txt")"
|
|
57
|
-
check "init: config max_passes=2 wins over default" \
|
|
58
|
-
"$(jq -e '.caps.max_passes == 2 and .caps.diff_cap_lines == 10' <<<"$out" >/dev/null; echo $?)"
|
|
59
|
-
|
|
60
|
-
out="$(SOMI_CODE_LOOP_MAX_PASSES=5 node "$LOOP" init --force --slug demo --loop code --iteration 1.1 --files "src/a.txt")"
|
|
61
|
-
check "init: env beats config" \
|
|
62
|
-
"$(jq -e '.caps.max_passes == 5' <<<"$out" >/dev/null; echo $?)"
|
|
63
|
-
|
|
64
|
-
out="$(node "$LOOP" init --force --slug demo --loop code --iteration 1.1 --max-passes 1 --diff-cap 6 --files "src/a.txt")"
|
|
65
|
-
check "init: CLI flag beats env and config" \
|
|
66
|
-
"$(jq -e '.caps.max_passes == 1 and .caps.diff_cap_lines == 6' <<<"$out" >/dev/null; echo $?)"
|
|
67
|
-
|
|
68
|
-
expect_exit "init: refuses to clobber a running loop without --force" 64 \
|
|
69
|
-
node "$LOOP" init --slug demo --loop code --iteration 1.1 --files "src/a.txt"
|
|
70
|
-
|
|
71
|
-
# --- somi-loop: a brief-only work item (plan dir without phases/) needs the approved tier record ---
|
|
72
|
-
mkdir -p .somi/plans/bo
|
|
73
|
-
printf 'brief one\n' > .somi/plans/bo/brief.md
|
|
74
|
-
TIER="$ROOT/scripts/somi-tier.mjs"
|
|
75
|
-
node -e 'const s={};for(const k of ["T1","T2","T3","T4","T5"])s[k]={value:k!=="T2",evidence:"e"};Object.assign(s,{sensitive_core:{value:false,evidence:"e"},hard_surface:{value:false,evidence:"e"},design_open:{value:false,evidence:"e"},open_questions:{value:0,evidence:"e"},acceptance_testable:{value:true,evidence:"e"},modules_touched:{value:1,evidence:"e"},est_files:{value:2,evidence:"e"},est_diff_lines:{value:80,evidence:"e"},existing_work_item:{value:false,evidence:"e"},brief_exists:{value:false,evidence:"e"}});console.log(JSON.stringify(s))' > "$TMP/small-signals.json"
|
|
76
|
-
expect_exit "brief-only: refused with no tier record" 64 \
|
|
77
|
-
node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files ".somi/plans/bo/brief.md"
|
|
78
|
-
node "$TIER" resolve --signals "$TMP/small-signals.json" --record bo --project-dir "$REPO" >/dev/null
|
|
79
|
-
check "brief-only: tier record is small" "$(jq -e '.tier == "small"' .somi/somi-state/tier/bo.json >/dev/null; echo $?)"
|
|
80
|
-
expect_exit "brief-only: refused when sized but not approved" 64 \
|
|
81
|
-
node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files ".somi/plans/bo/brief.md"
|
|
82
|
-
node "$TIER" approve --slug bo --project-dir "$REPO" >/dev/null
|
|
83
|
-
expect_exit "brief-only: accepted once approved" 0 \
|
|
84
|
-
node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files ".somi/plans/bo/brief.md"
|
|
85
|
-
printf 'brief two\n' > .somi/plans/bo/brief.md
|
|
86
|
-
expect_exit "brief-only: refused once the brief changed after approval" 64 \
|
|
87
|
-
node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files ".somi/plans/bo/brief.md"
|
|
88
|
-
mkdir -p .somi/plans/bo/phases
|
|
89
|
-
expect_exit "a plan with phases/ is unaffected" 0 \
|
|
90
|
-
node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files "src/a.txt"
|
|
91
|
-
out="$(node "$LOOP" init --force --slug bo --loop code --iteration 1.1 --files "src/a.txt")"
|
|
92
|
-
check "review lens: a record proven free of untrusted input and the core asks for no lens" \
|
|
93
|
-
"$(jq -e '.review_min == null' <<<"$out" >/dev/null && jq -e '.security_lens == false' .somi/somi-state/tier/bo.json >/dev/null; echo $?)"
|
|
94
|
-
jq '.T3.value = false' "$TMP/small-signals.json" > "$TMP/lens-signals.json"
|
|
95
|
-
node "$TIER" resolve --signals "$TMP/lens-signals.json" --record lens --project-dir "$REPO" >/dev/null
|
|
96
|
-
check "review lens: untrusted input alone stays small and records the security lens" \
|
|
97
|
-
"$(jq -e '.tier == "small" and .security_lens == true' .somi/somi-state/tier/lens.json >/dev/null; echo $?)"
|
|
98
|
-
mkdir -p .somi/plans/lens/phases
|
|
99
|
-
out="$(node "$LOOP" init --force --slug lens --loop code --iteration 1.1 --files "src/a.txt")"
|
|
100
|
-
check "review lens: init carries review_min security from the tier record" "$(jq -e '.review_min == "security"' <<<"$out" >/dev/null; echo $?)"
|
|
101
|
-
out="$(node "$LOOP" pass --slug lens --iteration 1.1)"
|
|
102
|
-
check "review lens: every pass repeats review_min" "$(jq -e '.pass == 1 and .review_min == "security"' <<<"$out" >/dev/null; echo $?)"
|
|
103
|
-
out="$(node "$LOOP" init --force --slug lens --loop plan --iteration 1.1)"
|
|
104
|
-
check "review lens: a plan loop carries no review_min" "$(jq -e '.review_min == null' <<<"$out" >/dev/null; echo $?)"
|
|
105
|
-
rm -rf .somi/plans/bo .somi/plans/lens .somi/somi-state/tier
|
|
106
|
-
|
|
107
|
-
# --- somi-loop: review scope (delta re-review from pass 2; full on the first and the last pass) ---
|
|
108
|
-
node "$LOOP" init --force --slug scope --loop code --iteration 1.1 --max-passes 3 --files "src/" >/dev/null
|
|
109
|
-
node "$LOOP" pass --slug scope --iteration 1.1 >/dev/null
|
|
110
|
-
out="$(node "$LOOP" review-scope --slug scope --iteration 1.1)"
|
|
111
|
-
check "review scope: pass 1 is reviewed in full" "$(jq -e '.scope == "full" and .why == "first-pass"' <<<"$out" >/dev/null; echo $?)"
|
|
112
|
-
idx_before="$(git ls-files -s | sha256sum)"; staged_before="$(git diff --cached --name-only | sha256sum)"
|
|
113
|
-
node "$LOOP" record-pass --slug scope --iteration 1.1 --verdict request-changes --blockers 0 --majors 1 >/dev/null
|
|
114
|
-
check "review scope: record-pass stores the reviewed tree" "$(node "$LOOP" stats --slug scope --iteration 1.1 | jq -e '.history[0].tree | test("^[0-9a-f]{40}$")' >/dev/null; echo $?)"
|
|
115
|
-
check "review scope: snapshotting leaves the caller's index untouched" "$([[ "$(git ls-files -s | sha256sum)" == "$idx_before" && "$(git diff --cached --name-only | sha256sum)" == "$staged_before" ]]; echo $?)"
|
|
116
|
-
printf 'fixed\n' >> src/a.txt; printf 'new\n' > src/new-untracked.txt
|
|
117
|
-
node "$LOOP" pass --slug scope --iteration 1.1 >/dev/null
|
|
118
|
-
out="$(node "$LOOP" review-scope --slug scope --iteration 1.1)"
|
|
119
|
-
check "review scope: pass 2 sees only the delta since the reviewed tree, untracked files included" \
|
|
120
|
-
"$(jq -e '.scope == "delta" and .since_pass == 1 and (.files | sort) == ["src/a.txt","src/new-untracked.txt"]' <<<"$out" >/dev/null; echo $?)"
|
|
121
|
-
check "review scope: the delta's trees reproduce the change" "$(git diff "$(jq -r .from <<<"$out")" "$(jq -r .to <<<"$out")" -- src/a.txt | grep -qx '+fixed'; echo $?)"
|
|
122
|
-
out="$(SOMI_CODE_LOOP_REVIEW_SCOPE=full node "$LOOP" review-scope --slug scope --iteration 1.1)"
|
|
123
|
-
check "review scope: SOMI_CODE_LOOP_REVIEW_SCOPE=full restores full re-review" "$(jq -e '.scope == "full" and .why == "setting"' <<<"$out" >/dev/null; echo $?)"
|
|
124
|
-
printf '{"code_loop": {"review_scope": "full"}}\n' > .somi/config.json
|
|
125
|
-
out="$(node "$LOOP" review-scope --slug scope --iteration 1.1)"
|
|
126
|
-
check "review scope: code_loop.review_scope full in config restores full re-review" "$(jq -e '.scope == "full"' <<<"$out" >/dev/null; echo $?)"
|
|
127
|
-
printf '{"code_loop": {"max_passes": 2, "diff_cap_lines": 10}}\n' > .somi/config.json
|
|
128
|
-
expect_exit "review scope: an unknown setting is refused" 64 env SOMI_CODE_LOOP_REVIEW_SCOPE=partial node "$LOOP" review-scope --slug scope --iteration 1.1
|
|
129
|
-
node "$LOOP" record-pass --slug scope --iteration 1.1 --verdict request-changes --blockers 0 --majors 1 >/dev/null
|
|
130
|
-
node "$LOOP" pass --slug scope --iteration 1.1 >/dev/null
|
|
131
|
-
out="$(node "$LOOP" review-scope --slug scope --iteration 1.1)"
|
|
132
|
-
check "review scope: the last allowed pass is reviewed in full" "$(jq -e '.scope == "full" and .why == "last-pass"' <<<"$out" >/dev/null; echo $?)"
|
|
133
|
-
git checkout -q -- src/a.txt; rm -f src/new-untracked.txt
|
|
134
|
-
|
|
135
|
-
# --- somi-loop: a /ship-loop run's wall-time budget, enforced at every pass on the slug ---
|
|
136
|
-
out="$(node "$LOOP" run-start --slug clock)"
|
|
137
|
-
check "run-start: without a budget the start is recorded and max_minutes is null" "$(jq -e '.max_minutes == null and (.started | test("T"))' <<<"$out" >/dev/null; echo $?)"
|
|
138
|
-
node "$LOOP" init --force --slug clock --loop plan >/dev/null
|
|
139
|
-
expect_exit "pass: no budget, no time stop" 0 node "$LOOP" pass --slug clock
|
|
140
|
-
out="$(node "$LOOP" run-start --slug clock --max-minutes 30)"
|
|
141
|
-
check "run-start: a resumed run keeps its clock and budget" "$(jq -e '.resumed == true and .max_minutes == null' <<<"$out" >/dev/null; echo $?)"
|
|
142
|
-
out="$(SOMI_SHIP_LOOP_MAX_MINUTES=30 node "$LOOP" run-start --force --slug clock)"
|
|
143
|
-
check "run-start: the env budget is recorded" "$(jq -e '.max_minutes == 30' <<<"$out" >/dev/null; echo $?)"
|
|
144
|
-
expect_exit "pass: inside the budget" 0 node "$LOOP" pass --slug clock
|
|
145
|
-
jq '.started = "2000-01-01T00:00:00.000Z"' .somi/somi-state/run/clock.json > "$TMP/clock.json" && cp "$TMP/clock.json" .somi/somi-state/run/clock.json
|
|
146
|
-
expect_exit "pass: an exhausted time budget stops every loop on the slug (exit 4)" 4 node "$LOOP" pass --slug clock
|
|
147
|
-
check "pass: the refused pass is not counted" "$(node "$LOOP" stats --slug clock | jq -e '.pass == 2' >/dev/null; echo $?)"
|
|
148
|
-
jq '.started = "not a date"' .somi/somi-state/run/clock.json > "$TMP/clock.json" && cp "$TMP/clock.json" .somi/somi-state/run/clock.json
|
|
149
|
-
expect_exit "pass: an unreadable start fails closed" 4 node "$LOOP" pass --slug clock
|
|
150
|
-
expect_exit "run-start: a zero budget is refused" 64 node "$LOOP" run-start --force --slug clock --max-minutes 0
|
|
151
|
-
expect_exit "run-start: a malformed budget is refused" 64 node "$LOOP" run-start --force --slug clock --max-minutes soon
|
|
152
|
-
rm -rf .somi/somi-state/run
|
|
153
|
-
|
|
154
|
-
# --- somi-loop: the dispatch record is the resolver's answer, never the caller's claim ---
|
|
155
|
-
out="$(node "$LOOP" record-dispatch --slug scope --iteration 1.1 --agent somi-coder)"
|
|
156
|
-
check "record-dispatch: claude-code entry carries tier, model and enforced from the resolver" \
|
|
157
|
-
"$(jq -e '.agent == "somi-coder" and .host == "claude-code" and .pass == 3 and (.tier | type) == "string" and .enforced == true and (.model | type) == "string"' <<<"$out" >/dev/null; echo $?)"
|
|
158
|
-
out="$(node "$LOOP" record-dispatch --slug scope --iteration 1.1 --agent somi-reviewer --host copilot)"
|
|
159
|
-
check "record-dispatch: an unmapped host is recorded as not enforced, with the reason" \
|
|
160
|
-
"$(jq -e '.host == "copilot" and .model == null and .enforced == false and (.reason | test("no model mapping"))' <<<"$out" >/dev/null; echo $?)"
|
|
161
|
-
expect_exit "record-dispatch: an unknown agent is refused with the resolver's code" 65 node "$LOOP" record-dispatch --slug scope --iteration 1.1 --agent reviewer
|
|
162
|
-
expect_exit "record-dispatch: --agent is required" 64 node "$LOOP" record-dispatch --slug scope --iteration 1.1
|
|
163
|
-
out="$(node "$LOOP" finish --slug scope --iteration 1.1 --status done)"
|
|
164
|
-
check "finish: the summary lists every recorded dispatch" "$(jq -e '(.dispatches | length) == 2 and .dispatches[1].enforced == false' <<<"$out" >/dev/null; echo $?)"
|
|
165
|
-
|
|
166
|
-
# --- somi-loop: pass counting ---------------------------------------------------
|
|
167
|
-
node "$LOOP" pass --slug demo --iteration 1.1 >/dev/null
|
|
168
|
-
expect_exit "pass: exceeding max_passes exits 2" 2 \
|
|
169
|
-
node "$LOOP" pass --slug demo --iteration 1.1
|
|
170
|
-
|
|
171
|
-
# --- somi-loop: weighted diff + exclusions --------------------------------------
|
|
172
|
-
printf 'one\ntwo\nthree\n' > src/a.txt # in-scope: 2 added lines → weight 2
|
|
173
|
-
printf 'artifact churn\n' >> .somi/notes.md # excluded entirely
|
|
174
|
-
out="$(node "$LOOP" check-diff --slug demo --iteration 1.1)"
|
|
175
|
-
check "check-diff: in-scope lines counted, .somi excluded" \
|
|
176
|
-
"$(jq -e '.diff_lines == 2 and .weighted_lines == 2 and (.out_of_scope | length) == 0' <<<"$out" >/dev/null; echo $?)"
|
|
177
|
-
|
|
178
|
-
printf 'one\ntwo\nthree\n' > src/b.txt # out-of-scope: 2 added lines → weight 4; total weighted 6 = cap
|
|
179
|
-
out="$(node "$LOOP" check-diff --slug demo --iteration 1.1)"
|
|
180
|
-
check "check-diff: out-of-scope counts double, at cap is ok" \
|
|
181
|
-
"$(jq -e '.weighted_lines == 6 and .out_of_scope == ["src/b.txt"]' <<<"$out" >/dev/null; echo $?)"
|
|
182
|
-
|
|
183
|
-
printf 'four\n' >> src/b.txt # weighted 8 > cap 6
|
|
184
|
-
expect_exit "check-diff: over weighted cap exits 3" 3 \
|
|
185
|
-
node "$LOOP" check-diff --slug demo --iteration 1.1
|
|
186
|
-
|
|
187
|
-
# `git diff` reads the index and tracked work-tree paths, so a file git
|
|
188
|
-
# has never been told about is in NEITHER -- a brand-new file counted zero until
|
|
189
|
-
# someone ran `git add`, and the cap under-measured by the whole size of every
|
|
190
|
-
# file an iteration introduced. Silently, and in the direction that lets work
|
|
191
|
-
# through. Measured on the same tree before and after the file exists, rather
|
|
192
|
-
# than asserted against a hardcoded total that would drift with the block above.
|
|
193
|
-
node "$LOOP" init --force --slug untracked --loop code --iteration 1.1 \
|
|
194
|
-
--files "src/new.txt" --diff-cap 100 >/dev/null
|
|
195
|
-
before="$(node "$LOOP" check-diff --slug untracked --iteration 1.1 | jq .diff_lines)"
|
|
196
|
-
printf 'x\ny\nz\n' > src/new.txt # untracked: never `git add`ed
|
|
197
|
-
after="$(node "$LOOP" check-diff --slug untracked --iteration 1.1 | jq .diff_lines)"
|
|
198
|
-
check "check-diff: an untracked file counts its lines (F-220)" \
|
|
199
|
-
"$([[ "$after" == "$((before + 3))" ]]; echo $?)"
|
|
200
|
-
|
|
201
|
-
printf 'churn\n' > .somi/untracked-note.md # excluded pathspec, must stay 0
|
|
202
|
-
after2="$(node "$LOOP" check-diff --slug untracked --iteration 1.1 | jq .diff_lines)"
|
|
203
|
-
check "check-diff: untracked .somi files stay excluded (F-220)" \
|
|
204
|
-
"$([[ "$after2" == "$after" ]]; echo $?)"
|
|
205
|
-
|
|
206
|
-
printf 'a\nb\nc\nd\n' > "src/é tab.txt" # untracked, non-ASCII and a tab in the name: git quotes it unless asked not to
|
|
207
|
-
out="$(node "$LOOP" check-diff --slug untracked --iteration 1.1)"
|
|
208
|
-
check "check-diff: an untracked file with a non-ASCII and tab name is counted and named, unquoted" \
|
|
209
|
-
"$([[ "$(jq -r .diff_lines <<<"$out")" == "$((after2 + 4))" ]] && jq -e '.out_of_scope | index("src/é\ttab.txt") != null' <<<"$out" >/dev/null; echo $?)"
|
|
210
|
-
rm -f "src/é tab.txt"
|
|
211
|
-
|
|
212
|
-
echo '*.dat -diff' > .gitattributes; seq 1 5000 > src/x.dat # untracked, and a -diff attribute makes git print it as binary
|
|
213
|
-
check "check-diff: an untracked 5000-line file hidden by a -diff attribute is counted (5001 with the attributes file)" \
|
|
214
|
-
"$([[ "$(node "$LOOP" check-diff --slug untracked --iteration 1.1 | jq .diff_lines)" == "$((after2 + 5001))" ]]; echo $?)"
|
|
215
|
-
rm -f .gitattributes src/x.dat
|
|
216
|
-
|
|
217
|
-
# --- somi-loop: record/finish/resume (session-death recovery) -------------------
|
|
218
|
-
node "$LOOP" record-pass --slug demo --iteration 1.1 --verdict request-changes --blockers 0 --majors 2 >/dev/null
|
|
219
|
-
out="$(node "$LOOP" resume --slug demo --iteration 1.1)"
|
|
220
|
-
check "resume: state survives with pass count and history" \
|
|
221
|
-
"$(jq -e '.pass == 1 and (.history | length) == 1 and .status == "running"' <<<"$out" >/dev/null; echo $?)"
|
|
222
|
-
node "$LOOP" finish --slug demo --iteration 1.1 --status stopped-diff-cap >/dev/null
|
|
223
|
-
out="$(node "$LOOP" stats --slug demo --iteration 1.1)"
|
|
224
|
-
check "finish: status recorded for the run ledger" \
|
|
225
|
-
"$(jq -e '.status == "stopped-diff-cap"' <<<"$out" >/dev/null; echo $?)"
|
|
226
|
-
|
|
227
|
-
# --- somi-loop: mid-loop cap re-resolution without --force ---------------
|
|
228
|
-
# commands/code-loop.md's documented remedy for a fired gate: "the user adjusts the
|
|
229
|
-
# env var explicitly and re-runs — the loop does not 'decide' to widen its own
|
|
230
|
-
# bounds." Before this fix, caps were resolved only at `init` and frozen into state:
|
|
231
|
-
# setting the env var and re-running `pass`/`check-diff` changed nothing, and the
|
|
232
|
-
# only path that DID re-resolve (`init --force`) discarded pass history — the one
|
|
233
|
-
# thing a mid-loop raise must not do. This block is the regression guard: it fails
|
|
234
|
-
# red against the pre-fix scripts/somi-loop.mjs (verified by hand, not committed —
|
|
235
|
-
# see the coder's summary) and asserts the remedy now actually works, on the SAME
|
|
236
|
-
# subcommand, without losing baseline/history, with the raise persisted for audit.
|
|
237
|
-
#
|
|
238
|
-
# Runs against ITS OWN throwaway repo — $REPO above has, by this point, accumulated
|
|
239
|
-
# scenario-specific mutations to src/a.txt and src/b.txt plus an untracked src/new.txt
|
|
240
|
-
# from earlier sections; none are in capfix's iteration_files, so every one of them
|
|
241
|
-
# would count double against its narrow 4-line cap. Same reasoning as the golden
|
|
242
|
-
# section further down, which isolates itself for exactly this reason.
|
|
243
|
-
F29_REPO="$TMP/f29-repo"
|
|
244
|
-
mkdir -p "$F29_REPO/src" "$F29_REPO/.somi"
|
|
245
|
-
(
|
|
246
|
-
cd "$F29_REPO"
|
|
247
|
-
git init -q -b main
|
|
248
|
-
git config user.email t@t && git config user.name t
|
|
249
|
-
printf 'one\n' > src/a.txt
|
|
250
|
-
git add -A && git commit -qm init
|
|
251
|
-
)
|
|
252
|
-
export CLAUDE_PROJECT_DIR="$F29_REPO"
|
|
253
|
-
cd "$F29_REPO"
|
|
254
|
-
unset SOMI_CODE_LOOP_MAX_PASSES SOMI_CODE_LOOP_DIFF_CAP 2>/dev/null || true
|
|
255
|
-
|
|
256
|
-
node "$LOOP" init --slug capfix --loop code --iteration 1.1 \
|
|
257
|
-
--files "src/capfix.txt" --max-passes 1 --diff-cap 4 >/dev/null
|
|
258
|
-
baseline_before="$(node "$LOOP" stats --slug capfix --iteration 1.1 | jq -r .baseline_sha)"
|
|
259
|
-
|
|
260
|
-
node "$LOOP" pass --slug capfix --iteration 1.1 >/dev/null # pass 1 of 1 — ok
|
|
261
|
-
node "$LOOP" record-pass --slug capfix --iteration 1.1 \
|
|
262
|
-
--verdict request-changes --blockers 0 --majors 1 >/dev/null
|
|
263
|
-
expect_exit "F-29: pass beyond max_passes still gates before any override" 2 \
|
|
264
|
-
node "$LOOP" pass --slug capfix --iteration 1.1
|
|
265
|
-
|
|
266
|
-
# `|| true` below: under `set -euo pipefail`, a bare `var=$(cmd)` that exits
|
|
267
|
-
# non-zero aborts the WHOLE suite right here with no test name and every check
|
|
268
|
-
# below unreported — reproduced by hand against the pre-fix script (exit 2,
|
|
269
|
-
# "max-passes-exceeded: pass 2 > cap 1"). `|| true` keeps a regression a reported
|
|
270
|
-
# `check` failure instead of a silent suite death.
|
|
271
|
-
out="$(SOMI_CODE_LOOP_MAX_PASSES=5 node "$LOOP" pass --slug capfix --iteration 1.1)" || true
|
|
272
|
-
check "F-29: env var re-run of the SAME subcommand (no --force) honours the raised cap" \
|
|
273
|
-
"$(jq -e '.max_passes == 5 and .pass == 2' <<<"$out" >/dev/null; echo $?)"
|
|
274
|
-
unset SOMI_CODE_LOOP_MAX_PASSES 2>/dev/null || true
|
|
275
|
-
|
|
276
|
-
out="$(node "$LOOP" stats --slug capfix --iteration 1.1)"
|
|
277
|
-
check "F-29: baseline_sha untouched by the override" \
|
|
278
|
-
"$([[ "$(jq -r .baseline_sha <<<"$out")" == "$baseline_before" ]]; echo $?)"
|
|
279
|
-
check "F-29: pass history from before the override survives (still 1 entry)" \
|
|
280
|
-
"$(jq -e '(.history | length) == 1 and .history[0].verdict == "request-changes"' <<<"$out" >/dev/null; echo $?)"
|
|
281
|
-
check "F-29: the raise is persisted as an auditable cap_overrides entry, after_pass recorded pre-increment" \
|
|
282
|
-
"$(jq -e '.cap_overrides | length == 1 and .[0].field == "max_passes" and .[0].from == 1 and .[0].to == 5 and .[0].source == "env" and .[0].after_pass == 1' <<<"$out" >/dev/null; echo $?)"
|
|
283
|
-
|
|
284
|
-
# Same shape for diff_cap_lines, via the CLI flag instead of the env var (the other
|
|
285
|
-
# documented-precedence entry point — see commands/code-loop.md).
|
|
286
|
-
printf 'one\ntwo\nthree\n' > src/capfix.txt # untracked, in-scope: +3 lines, under cap 4
|
|
287
|
-
out="$(node "$LOOP" check-diff --slug capfix --iteration 1.1)"
|
|
288
|
-
check "F-29: check-diff under the original cap needs no override" \
|
|
289
|
-
"$(jq -e '.cap == 4 and .weighted_lines == 3' <<<"$out" >/dev/null; echo $?)"
|
|
290
|
-
|
|
291
|
-
printf 'four\nfive\n' >> src/capfix.txt # now +5 lines, weighted 5 > cap 4
|
|
292
|
-
expect_exit "F-29: check-diff over the original cap still gates before any override" 3 \
|
|
293
|
-
node "$LOOP" check-diff --slug capfix --iteration 1.1
|
|
294
|
-
|
|
295
|
-
# Same `|| true` reasoning as the env-var re-run above — this bare substitution
|
|
296
|
-
# would exit 3 (diff-cap-exceeded) against the pre-fix script and abort the suite.
|
|
297
|
-
out="$(node "$LOOP" check-diff --slug capfix --iteration 1.1 --diff-cap 10)" || true
|
|
298
|
-
check "F-29: --diff-cap flag re-run of the SAME subcommand (no --force) honours the raised cap" \
|
|
299
|
-
"$(jq -e '.cap == 10 and .weighted_lines == 5' <<<"$out" >/dev/null; echo $?)"
|
|
300
|
-
|
|
301
|
-
out="$(node "$LOOP" stats --slug capfix --iteration 1.1)"
|
|
302
|
-
check "F-29: pass/history/baseline still untouched after the diff-cap override too" \
|
|
303
|
-
"$(jq -e '.pass == 2 and (.history | length) == 1' <<<"$out" >/dev/null; echo $?)"
|
|
304
|
-
check "F-29: baseline_sha still untouched after the diff-cap override" \
|
|
305
|
-
"$([[ "$(jq -r .baseline_sha <<<"$out")" == "$baseline_before" ]]; echo $?)"
|
|
306
|
-
check "F-29: both overrides are recorded, in order, in cap_overrides, after_pass recorded correctly" \
|
|
307
|
-
"$(jq -e '.cap_overrides | length == 2 and .[1].field == "diff_cap_lines" and .[1].from == 4 and .[1].to == 10 and .[1].source == "cli" and .[1].after_pass == 2' <<<"$out" >/dev/null; echo $?)"
|
|
308
|
-
|
|
309
|
-
# --- malformed cap values must be rejected, not silently coerced to NaN/null ----
|
|
310
|
-
# `Number()` on "1,000"/"unlimited"/"none" yields NaN, which is FALSE against BOTH
|
|
311
|
-
# gate comparisons (`cur + 1 > max`, `weighted > cap`) — the gate goes fail-open —
|
|
312
|
-
# and `JSON.stringify` then persists that NaN as `null`, which the next bare call
|
|
313
|
-
# falls through past (via firstDefined) to re-arm at the DEFAULT, with no
|
|
314
|
-
# cap_overrides entry recording the reversion. validateCap() rejects (exit 64)
|
|
315
|
-
# rather than coerces. Verified on both gates, both entry points (env AND flag).
|
|
316
|
-
before="$(node "$LOOP" stats --slug capfix --iteration 1.1)"
|
|
317
|
-
|
|
318
|
-
expect_exit "F-29: malformed SOMI_CODE_LOOP_MAX_PASSES env var is rejected (64), not silently disabled" 64 \
|
|
319
|
-
env SOMI_CODE_LOOP_MAX_PASSES=unlimited node "$LOOP" pass --slug capfix --iteration 1.1
|
|
320
|
-
expect_exit "F-29: malformed --max-passes flag is rejected (64), not silently disabled" 64 \
|
|
321
|
-
node "$LOOP" pass --slug capfix --iteration 1.1 --max-passes '1,000'
|
|
322
|
-
expect_exit "F-29: malformed SOMI_CODE_LOOP_DIFF_CAP env var is rejected (64), not silently disabled" 64 \
|
|
323
|
-
env SOMI_CODE_LOOP_DIFF_CAP=unlimited node "$LOOP" check-diff --slug capfix --iteration 1.1
|
|
324
|
-
expect_exit "F-29: malformed --diff-cap flag is rejected (64), not silently disabled" 64 \
|
|
325
|
-
node "$LOOP" check-diff --slug capfix --iteration 1.1 --diff-cap none
|
|
326
|
-
|
|
327
|
-
after="$(node "$LOOP" stats --slug capfix --iteration 1.1)"
|
|
328
|
-
check "F-29: every rejected malformed value left caps/cap_overrides/pass/history byte-identical" \
|
|
329
|
-
"$([[ "$before" == "$after" ]]; echo $?)"
|
|
330
|
-
|
|
331
|
-
out="$(node "$LOOP" finish --slug capfix --iteration 1.1 --status stopped-max-passes-exceeded)"
|
|
332
|
-
check "F-29: finish's stdout surfaces cap_overrides too, not just the gitignored state file" \
|
|
333
|
-
"$(jq -e '.cap_overrides | length == 2' <<<"$out" >/dev/null; echo $?)"
|
|
334
|
-
# Deliberately NOT "stopped-diff-cap" (the pre-existing spelling two blocks up, at
|
|
335
|
-
# line 116) — that bare reason matches neither CAP_BREACH_STATUSES
|
|
336
|
-
# (tests/evals/lib/convergence.mjs) nor commands/code-loop.md's documented status
|
|
337
|
-
# list; a separate open item, not to be copied here.
|
|
338
|
-
|
|
339
|
-
# --- somi-loop (plan): mirrors the code-loop block above for `--loop plan` -
|
|
340
|
-
# Plan loops have exactly one hard gate (`max_passes`); `diff_cap_lines` always
|
|
341
|
-
# short-circuits to 0 for the plan family in reresolveCap()/resolveInitCap(), so
|
|
342
|
-
# `--diff-cap` must be provably inert regardless of what's passed — asserted below
|
|
343
|
-
# rather than only "verified by hand" as pass 1's review left it.
|
|
344
|
-
PLAN29_REPO="$TMP/plan29-repo"
|
|
345
|
-
mkdir -p "$PLAN29_REPO/src" "$PLAN29_REPO/.somi"
|
|
346
|
-
(
|
|
347
|
-
cd "$PLAN29_REPO"
|
|
348
|
-
git init -q -b main
|
|
349
|
-
git config user.email t@t && git config user.name t
|
|
350
|
-
printf 'one\n' > src/a.txt
|
|
351
|
-
git add -A && git commit -qm init
|
|
352
|
-
)
|
|
353
|
-
export CLAUDE_PROJECT_DIR="$PLAN29_REPO"
|
|
354
|
-
cd "$PLAN29_REPO"
|
|
355
|
-
unset SOMI_PLAN_LOOP_MAX_PASSES 2>/dev/null || true
|
|
356
|
-
|
|
357
|
-
node "$LOOP" init --slug planfix --loop plan --max-passes 1 >/dev/null
|
|
358
|
-
plan_baseline_before="$(node "$LOOP" stats --slug planfix | jq -r .baseline_sha)"
|
|
359
|
-
|
|
360
|
-
node "$LOOP" pass --slug planfix >/dev/null # pass 1 of 1 — ok
|
|
361
|
-
expect_exit "F-29 (plan): pass beyond max_passes still gates before any override" 2 \
|
|
362
|
-
node "$LOOP" pass --slug planfix
|
|
363
|
-
|
|
364
|
-
out="$(SOMI_PLAN_LOOP_MAX_PASSES=5 node "$LOOP" pass --slug planfix)" || true
|
|
365
|
-
check "F-29 (plan): env var re-run of the SAME subcommand (no --force) honours the raised cap" \
|
|
366
|
-
"$(jq -e '.max_passes == 5 and .pass == 2' <<<"$out" >/dev/null; echo $?)"
|
|
367
|
-
unset SOMI_PLAN_LOOP_MAX_PASSES 2>/dev/null || true
|
|
368
|
-
|
|
369
|
-
out="$(node "$LOOP" stats --slug planfix)"
|
|
370
|
-
check "F-29 (plan): baseline_sha untouched by the override" \
|
|
371
|
-
"$([[ "$(jq -r .baseline_sha <<<"$out")" == "$plan_baseline_before" ]]; echo $?)"
|
|
372
|
-
check "F-29 (plan): the raise is persisted as an auditable cap_overrides entry" \
|
|
373
|
-
"$(jq -e '.cap_overrides | length == 1 and .[0].field == "max_passes" and .[0].from == 1 and .[0].to == 5 and .[0].source == "env" and .[0].after_pass == 1' <<<"$out" >/dev/null; echo $?)"
|
|
374
|
-
|
|
375
|
-
out="$(node "$LOOP" check-diff --slug planfix --diff-cap 999999)"
|
|
376
|
-
check "F-29 (plan): --diff-cap is inert on a plan loop — cap stays 0 regardless" \
|
|
377
|
-
"$(jq -e '.cap == 0' <<<"$out" >/dev/null; echo $?)"
|
|
378
|
-
out="$(node "$LOOP" stats --slug planfix)"
|
|
379
|
-
check "F-29 (plan): the inert --diff-cap flag records no cap_overrides entry" \
|
|
380
|
-
"$(jq -e '.cap_overrides | length == 1' <<<"$out" >/dev/null; echo $?)"
|
|
381
|
-
|
|
382
|
-
out="$(node "$LOOP" finish --slug planfix --status stopped-max-passes-exceeded)"
|
|
383
|
-
check "F-29 (plan): finish's stdout surfaces cap_overrides too" \
|
|
384
|
-
"$(jq -e '.cap_overrides | length == 1' <<<"$out" >/dev/null; echo $?)"
|
|
385
|
-
|
|
386
|
-
# Restore the shared $REPO context for every section below.
|
|
387
|
-
export CLAUDE_PROJECT_DIR="$REPO"
|
|
388
|
-
cd "$REPO"
|
|
389
|
-
|
|
390
|
-
# --- somi-findings: identity + breaker semantics --------------------------------
|
|
391
|
-
F1='[{"file":"src/a.txt","symbol":"HandleWebhook","title":"Missing rate limit on retry path","severity":"Major","confidence":"High"}]'
|
|
392
|
-
|
|
393
|
-
out="$(printf '%s' "$F1" | node "$FINDINGS" record --slug demo --review r1.md --run RUN1 --pass 1)"
|
|
394
|
-
check "record: first sighting is new" \
|
|
395
|
-
"$(jq -e '.state == "new" and .id == "F-1"' <<<"$out" >/dev/null; echo $?)"
|
|
396
|
-
|
|
397
|
-
# Same locus, different line/wording case, next consecutive pass → breaker (exit 5).
|
|
398
|
-
F1b='[{"file":"src/a.txt","symbol":"handlewebhook","title":"missing rate limit on retry path","severity":"Major"}]'
|
|
399
|
-
got=0; out="$(printf '%s' "$F1b" | node "$FINDINGS" record --slug demo --review r2.md --run RUN1 --pass 2)" || got=$?
|
|
400
|
-
check "record: consecutive-pass recurrence exits 5" "$([[ "$got" == "5" ]]; echo $?)"
|
|
401
|
-
check "record: recurrence classified consecutive" \
|
|
402
|
-
"$(jq -e '.state == "known" and .recurring_consecutive == true' <<<"$out" >/dev/null; echo $?)"
|
|
403
|
-
|
|
404
|
-
# A different run (e.g. a later /code-loop) seeing the same open finding → cross-run.
|
|
405
|
-
got=0; out="$(printf '%s' "$F1" | node "$FINDINGS" record --slug demo --review r3.md --run RUN2 --pass 1)" || got=$?
|
|
406
|
-
check "record: cross-run recurrence flagged, not consecutive" \
|
|
407
|
-
"$(jq -e '.recurring_cross_run == true and .recurring_consecutive == false' <<<"$out" >/dev/null; echo $?)"
|
|
408
|
-
check "record: cross-run alone does not exit 5" "$([[ "$got" == "0" ]]; echo $?)"
|
|
409
|
-
|
|
410
|
-
# Resolve → open list empties → re-report of same locus becomes a NEW finding.
|
|
411
|
-
node "$FINDINGS" resolve --slug demo --id F-1 --status fixed --by r4.md >/dev/null
|
|
412
|
-
out="$(node "$FINDINGS" open --slug demo)"
|
|
413
|
-
check "resolve: open list is empty after fix" \
|
|
414
|
-
"$(jq -e 'length == 0' <<<"$out" >/dev/null; echo $?)"
|
|
415
|
-
out="$(printf '%s' "$F1" | node "$FINDINGS" record --slug demo --review r5.md --run RUN3 --pass 1)"
|
|
416
|
-
check "record: resolved locus re-reported becomes a new finding (F-2)" \
|
|
417
|
-
"$(jq -e '.state == "new" and .id == "F-2"' <<<"$out" >/dev/null; echo $?)"
|
|
418
|
-
|
|
419
|
-
# Ledger lives with the review artifacts.
|
|
420
|
-
check "ledger: stored under .somi/reviews/<slug>/findings.json" \
|
|
421
|
-
"$([[ -f "$REPO/.somi/reviews/demo/findings.json" ]]; echo $?)"
|
|
422
|
-
|
|
423
|
-
# --- somi-findings: record surfaces a clean error, not a raw crash, when the stdin
|
|
424
|
-
# read itself fails (fix-stdin-read-crash: fs.readFileSync(0) threw uncaught on any OS
|
|
425
|
-
# error — e.g. Windows' EAGAIN for a TTY stdin — bypassing this script's own die()/exit-64
|
|
426
|
-
# convention). Mocked platform-independently via a --require preload; see the fixture's
|
|
427
|
-
# header comment. -----------------------------------------------------------------------
|
|
428
|
-
STDIN_THROW_MOCK="$ROOT/tests/scripts/fixtures/mock-stdin-read-throw.cjs"
|
|
429
|
-
got=0
|
|
430
|
-
err="$(node --require "$STDIN_THROW_MOCK" "$FINDINGS" record --slug demo --review r6.md --run RUN4 --pass 1 2>&1 >/dev/null)" || got=$?
|
|
431
|
-
check "record: stdin read failure exits via die() (64), not an uncaught crash" "$([[ "$got" == "64" ]]; echo $?)"
|
|
432
|
-
check "record: stdin read failure prints the die() message, not a raw stack trace" \
|
|
433
|
-
"$([[ "$err" == "somi-findings: "* && "$err" != *"at Object."* ]]; echo $?)"
|
|
434
|
-
|
|
435
|
-
# --- somi-check: portable working-tree guard -------------------------------------
|
|
436
|
-
CHECK="$ROOT/scripts/somi-check.mjs"
|
|
437
|
-
|
|
438
|
-
printf 'KEY=1\n' > .env && git add .env
|
|
439
|
-
expect_exit "somi-check: staged .env fails" 1 node "$CHECK" --staged
|
|
440
|
-
git rm -q --cached .env && rm .env
|
|
441
|
-
|
|
442
|
-
printf 'KEY=\n' > .env.example && git add .env.example
|
|
443
|
-
expect_exit "somi-check: staged .env.example passes" 0 node "$CHECK" --staged
|
|
444
|
-
git rm -q --cached .env.example && rm .env.example
|
|
445
|
-
|
|
446
|
-
printf '{}\n' > package-lock.json && git add package-lock.json
|
|
447
|
-
expect_exit "somi-check: lockfile without manifest fails" 1 node "$CHECK" --staged
|
|
448
|
-
printf '{"name":"t"}\n' > package.json && git add package.json
|
|
449
|
-
expect_exit "somi-check: lockfile WITH manifest passes" 0 node "$CHECK" --staged
|
|
450
|
-
git rm -q --cached package.json && rm package.json
|
|
451
|
-
printf '{"lockfiles": {"allow_edit": true}}\n' > .somi/config.json
|
|
452
|
-
expect_exit "somi-check: config allow_edit passes bare lockfile" 0 node "$CHECK" --staged
|
|
453
|
-
got=0; SOMI_ALLOW_LOCKFILES=0 node "$CHECK" --staged >/dev/null 2>&1 || got=$?
|
|
454
|
-
check "somi-check: env=0 beats config allow_edit" "$([[ "$got" == "1" ]]; echo $?)"
|
|
455
|
-
git rm -q --cached package-lock.json && rm package-lock.json
|
|
456
|
-
|
|
457
|
-
printf 'x\n# TODO(claude): fix me\n' > src/todo.txt && git add src/todo.txt
|
|
458
|
-
expect_exit "somi-check: staged TODO(claude) marker fails" 1 node "$CHECK" --staged
|
|
459
|
-
git rm -q --cached src/todo.txt && rm src/todo.txt
|
|
460
|
-
|
|
461
|
-
expect_exit "somi-check: clean staged set passes" 0 node "$CHECK" --staged
|
|
462
|
-
|
|
463
|
-
# --- golden snapshots: byte-level diff target for the Node port (additive) ------
|
|
464
|
-
#
|
|
465
|
-
# Everything above asserts *behavioral properties* (cap precedence, weighting,
|
|
466
|
-
# recurrence semantics) — sufficient to gate this bash implementation, but it gives
|
|
467
|
-
# the Node port no byte-level "does this match?" target. This section runs a
|
|
468
|
-
# second, independent, fully-scripted scenario against ITS OWN throwaway repo (kept
|
|
469
|
-
# separate from $REPO above, which by this point has accumulated a lot of
|
|
470
|
-
# scenario-specific mutations — reusing it would couple golden ordering to the
|
|
471
|
-
# inline assertions' ordering) and records each invocation's {argv, exit, stdout,
|
|
472
|
-
# stderr} — normalized — into a golden file. It never touches the checks above.
|
|
473
|
-
#
|
|
474
|
-
# Mode: `SOMI_GOLDEN_MODE=capture bash tests/scripts/run.sh` (re)writes the golden
|
|
475
|
-
# files under tests/scripts/goldens/; the default, `check` (every normal dev/CI
|
|
476
|
-
# run), replays the same scenario and fails loudly on any drift from what's
|
|
477
|
-
# committed. Once $LOOP/$FINDINGS point at the Node CLIs, `check` mode
|
|
478
|
-
# is exactly the parity gate: same scenario, same normalization, byte-for-byte
|
|
479
|
-
# comparison — a divergence here is a real behavior regression, not noise.
|
|
480
|
-
#
|
|
481
|
-
# Golden layout: one consolidated, pretty-printed JSON array per source script
|
|
482
|
-
# (tests/scripts/goldens/somi-loop.json, .../somi-findings.json) rather than one
|
|
483
|
-
# file per scenario — fewer files to keep in sync; each array element is still a
|
|
484
|
-
# self-contained {name, argv, exit, stdout, stderr} record, so a mismatch's `diff
|
|
485
|
-
# -u` output identifies the offending scenario by its "name" field without any
|
|
486
|
-
# extra tooling.
|
|
487
|
-
#
|
|
488
|
-
# Normalization masks ONLY values that legitimately vary run-to-run — never JSON
|
|
489
|
-
# key order, spacing, or field presence, since that IS the thing a Node port must
|
|
490
|
-
# reproduce exactly:
|
|
491
|
-
# - full ISO-8601 instants (YYYY-MM-DDTHH:MM:SSZ) -> <TS> (loop's started/at/finished)
|
|
492
|
-
# - bare dates (YYYY-MM-DD) -> <DATE> (findings' seen[].date)
|
|
493
|
-
# - 40-hex git SHAs -> <SHA> (loop's baseline_sha)
|
|
494
|
-
# - this golden run's own throwaway-repo path -> <DIR> (loop's state_file / jq input_filename)
|
|
495
|
-
# Order matters: instants are masked before bare dates, else the bare-date pattern
|
|
496
|
-
# would also eat the date portion of an instant, leaving a mangled "<DATE>T.....Z".
|
|
497
|
-
GOLDEN_DIR="$ROOT/tests/scripts/goldens"
|
|
498
|
-
GOLDEN_MODE="${SOMI_GOLDEN_MODE:-check}"
|
|
499
|
-
case "$GOLDEN_MODE" in
|
|
500
|
-
capture|check) ;;
|
|
501
|
-
*) echo "SOMI_GOLDEN_MODE must be 'capture' or 'check' (got: $GOLDEN_MODE)" >&2; exit 64 ;;
|
|
502
|
-
esac
|
|
503
|
-
mkdir -p "$GOLDEN_DIR"
|
|
504
|
-
|
|
505
|
-
GTMP="$TMP/goldens"
|
|
506
|
-
GREPO="$GTMP/repo"
|
|
507
|
-
mkdir -p "$GREPO/src" "$GREPO/.somi"
|
|
508
|
-
(
|
|
509
|
-
cd "$GREPO"
|
|
510
|
-
git init -q -b main
|
|
511
|
-
git config user.email t@t && git config user.name t
|
|
512
|
-
printf 'one\n' > src/a.txt
|
|
513
|
-
printf 'one\n' > src/b.txt
|
|
514
|
-
git add -A && git commit -qm init
|
|
515
|
-
)
|
|
516
|
-
export CLAUDE_PROJECT_DIR="$GREPO"
|
|
517
|
-
unset SOMI_CODE_LOOP_MAX_PASSES SOMI_CODE_LOOP_DIFF_CAP SOMI_CODE_LOOP_SEVERITY_FLOOR \
|
|
518
|
-
SOMI_PLAN_LOOP_MAX_PASSES SOMI_PLAN_LOOP_DIFF_CAP SOMI_PLAN_LOOP_SEVERITY_FLOOR 2>/dev/null || true
|
|
519
|
-
cd "$GREPO"
|
|
520
|
-
|
|
521
|
-
GSTEP_EXIT=0 GSTEP_STDOUT="" GSTEP_STDERR=""
|
|
522
|
-
golden_step() { # $@ = command (no stdin)
|
|
523
|
-
local out err rc=0
|
|
524
|
-
out="$(mktemp)"; err="$(mktemp)"
|
|
525
|
-
if "$@" >"$out" 2>"$err"; then rc=0; else rc=$?; fi
|
|
526
|
-
GSTEP_EXIT=$rc; GSTEP_STDOUT="$(cat "$out")"; GSTEP_STDERR="$(cat "$err")"
|
|
527
|
-
rm -f "$out" "$err"
|
|
528
|
-
}
|
|
529
|
-
golden_step_stdin() { # $1 = stdin payload, then command
|
|
530
|
-
local payload="$1"; shift
|
|
531
|
-
local out err rc=0
|
|
532
|
-
out="$(mktemp)"; err="$(mktemp)"
|
|
533
|
-
if printf '%s' "$payload" | "$@" >"$out" 2>"$err"; then rc=0; else rc=$?; fi
|
|
534
|
-
GSTEP_EXIT=$rc; GSTEP_STDOUT="$(cat "$out")"; GSTEP_STDERR="$(cat "$err")"
|
|
535
|
-
rm -f "$out" "$err"
|
|
536
|
-
}
|
|
537
|
-
golden_normalize() { # stdin -> normalized text on stdout
|
|
538
|
-
local text
|
|
539
|
-
text="$(cat)"
|
|
540
|
-
text="$(printf '%s' "$text" | sed -E \
|
|
541
|
-
-e 's/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z/<TS>/g' \
|
|
542
|
-
-e 's/[0-9]{4}-[0-9]{2}-[0-9]{2}/<DATE>/g' \
|
|
543
|
-
-e 's/[0-9a-f]{40}/<SHA>/g')"
|
|
544
|
-
printf '%s' "${text//$GTMP/<DIR>}"
|
|
545
|
-
}
|
|
546
|
-
golden_case() { # $1=script $2=name, then argv... (uses GSTEP_* set by the caller)
|
|
547
|
-
local script="$1" name="$2"; shift 2
|
|
548
|
-
local argv_json norm_out norm_err
|
|
549
|
-
argv_json="$(printf '%s\n' "$@" | jq -R . | jq -s .)"
|
|
550
|
-
norm_out="$(printf '%s' "$GSTEP_STDOUT" | golden_normalize)"
|
|
551
|
-
norm_err="$(printf '%s' "$GSTEP_STDERR" | golden_normalize)"
|
|
552
|
-
jq -nc --arg script "$script" --arg name "$name" --argjson argv "$argv_json" \
|
|
553
|
-
--argjson exit "$GSTEP_EXIT" --arg stdout "$norm_out" --arg stderr "$norm_err" \
|
|
554
|
-
'{script:$script, name:$name, argv:$argv, exit:$exit, stdout:$stdout, stderr:$stderr}'
|
|
555
|
-
}
|
|
556
|
-
golden_case_stdin() { # $1=script $2=name $3=stdin, then argv...
|
|
557
|
-
local script="$1" name="$2" stdin_payload="$3"; shift 3
|
|
558
|
-
local argv_json norm_out norm_err
|
|
559
|
-
argv_json="$(printf '%s\n' "$@" | jq -R . | jq -s .)"
|
|
560
|
-
norm_out="$(printf '%s' "$GSTEP_STDOUT" | golden_normalize)"
|
|
561
|
-
norm_err="$(printf '%s' "$GSTEP_STDERR" | golden_normalize)"
|
|
562
|
-
jq -nc --arg script "$script" --arg name "$name" --argjson argv "$argv_json" --arg stdin "$stdin_payload" \
|
|
563
|
-
--argjson exit "$GSTEP_EXIT" --arg stdout "$norm_out" --arg stderr "$norm_err" \
|
|
564
|
-
'{script:$script, name:$name, argv:$argv, stdin:$stdin, exit:$exit, stdout:$stdout, stderr:$stderr}'
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
LOOP_GOLDEN_CASES=()
|
|
568
|
-
FINDINGS_GOLDEN_CASES=()
|
|
569
|
-
|
|
570
|
-
# --- somi-loop: init, pass, check-diff (in/out-of-scope, at/over cap), record-pass, resume, finish, stats
|
|
571
|
-
printf '{"code_loop": {"max_passes": 2, "diff_cap_lines": 10}}\n' > .somi/config.json
|
|
572
|
-
|
|
573
|
-
golden_step node "$LOOP" init --slug g --loop code --iteration 1.1 --files "src/a.txt"
|
|
574
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "init: config-resolved caps" init --slug g --loop code --iteration 1.1 --files "src/a.txt")")
|
|
575
|
-
|
|
576
|
-
golden_step node "$LOOP" pass --slug g --iteration 1.1
|
|
577
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "pass: 1st pass (1 of 2)" pass --slug g --iteration 1.1)")
|
|
578
|
-
|
|
579
|
-
golden_step node "$LOOP" pass --slug g --iteration 1.1
|
|
580
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "pass: 2nd pass (2 of 2, at cap, allowed)" pass --slug g --iteration 1.1)")
|
|
581
|
-
|
|
582
|
-
golden_step node "$LOOP" pass --slug g --iteration 1.1
|
|
583
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "pass: 3rd pass exceeds max_passes (exit 2)" pass --slug g --iteration 1.1)")
|
|
584
|
-
|
|
585
|
-
printf 'one\ntwo\nthree\n' > src/a.txt # in-scope: +2 lines
|
|
586
|
-
golden_step node "$LOOP" check-diff --slug g --iteration 1.1
|
|
587
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "check-diff: in-scope only, under cap" check-diff --slug g --iteration 1.1)")
|
|
588
|
-
|
|
589
|
-
printf 'one\ntwo\nthree\nfour\nfive\n' > src/b.txt # out-of-scope: +4 lines -> weight 8; total 2+8=10 = cap
|
|
590
|
-
golden_step node "$LOOP" check-diff --slug g --iteration 1.1
|
|
591
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "check-diff: out-of-scope doubled, exactly at cap" check-diff --slug g --iteration 1.1)")
|
|
592
|
-
|
|
593
|
-
printf 'six\n' >> src/b.txt # +1 more out-of-scope line -> weight 12 > cap 10
|
|
594
|
-
golden_step node "$LOOP" check-diff --slug g --iteration 1.1
|
|
595
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "check-diff: over weighted cap (exit 3)" check-diff --slug g --iteration 1.1)")
|
|
596
|
-
|
|
597
|
-
golden_step node "$LOOP" record-pass --slug g --iteration 1.1 --verdict request-changes --blockers 0 --majors 2
|
|
598
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "record-pass: appends history entry" record-pass --slug g --iteration 1.1 --verdict request-changes --blockers 0 --majors 2)")
|
|
599
|
-
|
|
600
|
-
golden_step node "$LOOP" resume --slug g --iteration 1.1
|
|
601
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "resume: state with pass count and history" resume --slug g --iteration 1.1)")
|
|
602
|
-
|
|
603
|
-
golden_step node "$LOOP" finish --slug g --iteration 1.1 --status stopped-diff-cap
|
|
604
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "finish: records terminal status" finish --slug g --iteration 1.1 --status stopped-diff-cap)")
|
|
605
|
-
|
|
606
|
-
golden_step node "$LOOP" stats --slug g --iteration 1.1
|
|
607
|
-
LOOP_GOLDEN_CASES+=("$(golden_case somi-loop.sh "stats: full state ledger" stats --slug g --iteration 1.1)")
|
|
608
|
-
|
|
609
|
-
# --- somi-findings: record (new/consecutive/cross-run), resolve, open, reopen, get
|
|
610
|
-
GF1='[{"file":"src/a.txt","symbol":"HandleWebhook","title":"Missing rate limit on retry path","severity":"Major","confidence":"High"}]'
|
|
611
|
-
GF1b='[{"file":"src/a.txt","symbol":"handlewebhook","title":"missing rate limit on retry path","severity":"Major"}]'
|
|
612
|
-
|
|
613
|
-
golden_step_stdin "$GF1" node "$FINDINGS" record --slug gf --review r1.md --run RUN1 --pass 1
|
|
614
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case_stdin somi-findings.sh "record: first sighting is new (F-1)" "$GF1" record --slug gf --review r1.md --run RUN1 --pass 1)")
|
|
615
|
-
|
|
616
|
-
golden_step_stdin "$GF1b" node "$FINDINGS" record --slug gf --review r2.md --run RUN1 --pass 2
|
|
617
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case_stdin somi-findings.sh "record: consecutive-pass recurrence (exit 5)" "$GF1b" record --slug gf --review r2.md --run RUN1 --pass 2)")
|
|
618
|
-
|
|
619
|
-
golden_step_stdin "$GF1" node "$FINDINGS" record --slug gf --review r3.md --run RUN2 --pass 1
|
|
620
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case_stdin somi-findings.sh "record: cross-run recurrence (exit 0, not consecutive)" "$GF1" record --slug gf --review r3.md --run RUN2 --pass 1)")
|
|
621
|
-
|
|
622
|
-
golden_step node "$FINDINGS" resolve --slug gf --id F-1 --status fixed --by r4.md
|
|
623
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case somi-findings.sh "resolve: F-1 fixed" resolve --slug gf --id F-1 --status fixed --by r4.md)")
|
|
624
|
-
|
|
625
|
-
golden_step node "$FINDINGS" open --slug gf
|
|
626
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case somi-findings.sh "open: empty after resolve" open --slug gf)")
|
|
627
|
-
|
|
628
|
-
golden_step_stdin "$GF1" node "$FINDINGS" record --slug gf --review r5.md --run RUN3 --pass 1
|
|
629
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case_stdin somi-findings.sh "record: resolved locus re-reported becomes new (F-2)" "$GF1" record --slug gf --review r5.md --run RUN3 --pass 1)")
|
|
630
|
-
|
|
631
|
-
golden_step node "$FINDINGS" reopen --slug gf --id F-1 --by r6.md
|
|
632
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case somi-findings.sh "reopen: F-1 back to open" reopen --slug gf --id F-1 --by r6.md)")
|
|
633
|
-
|
|
634
|
-
golden_step node "$FINDINGS" get --slug gf --id F-1
|
|
635
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case somi-findings.sh "get: F-1 (reopened)" get --slug gf --id F-1)")
|
|
636
|
-
|
|
637
|
-
golden_step node "$FINDINGS" get --slug gf --id F-2
|
|
638
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case somi-findings.sh "get: F-2" get --slug gf --id F-2)")
|
|
639
|
-
|
|
640
|
-
# --- normalize_title edge cases: each isolated on its own fresh slug, so the locus
|
|
641
|
-
# key it produces is directly comparable (only the title varies). The empty-title
|
|
642
|
-
# case is pinned to REALITY, not an invented pass: `record` requires both {file,
|
|
643
|
-
# title} and dies 64 before ever calling normalize_title, so its golden is the
|
|
644
|
-
# usage-error shape, not a fabricated success.
|
|
645
|
-
golden_edge_case() { # $1=slug $2=label $3=title
|
|
646
|
-
local slug="$1" label="$2" title="$3" payload
|
|
647
|
-
payload="$(jq -nc --arg f src/a.txt --arg t "$title" '[{file:$f, title:$t}]')"
|
|
648
|
-
golden_step_stdin "$payload" node "$FINDINGS" record --slug "$slug" --review r.md --run R1 --pass 1
|
|
649
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case_stdin somi-findings.sh "normalize_title: $label — record" "$payload" record --slug "$slug" --review r.md --run R1 --pass 1)")
|
|
650
|
-
if [[ "$GSTEP_EXIT" == "0" ]]; then
|
|
651
|
-
golden_step node "$FINDINGS" get --slug "$slug" --id F-1
|
|
652
|
-
FINDINGS_GOLDEN_CASES+=("$(golden_case somi-findings.sh "normalize_title: $label — get (exposes key)" get --slug "$slug" --id F-1)")
|
|
653
|
-
fi
|
|
654
|
-
}
|
|
655
|
-
golden_edge_case edge-empty "empty title (dies 64, never reaches normalize_title)" ""
|
|
656
|
-
golden_edge_case edge-single "single word" "Bug"
|
|
657
|
-
golden_edge_case edge-many ">8 words truncates" "one two three four five six seven eight nine ten"
|
|
658
|
-
golden_edge_case edge-ws "leading/trailing whitespace" " Missing rate limit "
|
|
659
|
-
golden_edge_case edge-multispace "multiple internal spaces" "Missing rate limit"
|
|
660
|
-
golden_edge_case edge-punct "punctuation stripped" "Missing rate-limit! (on retry) path?"
|
|
661
|
-
|
|
662
|
-
# --- write (capture) or compare (check) ------------------------------------------
|
|
663
|
-
golden_compare() { # $1 = golden file path, $2 = freshly-captured JSON array content
|
|
664
|
-
local file="$1" content="$2"
|
|
665
|
-
total=$((total + 1))
|
|
666
|
-
if [[ "$GOLDEN_MODE" == "capture" ]]; then
|
|
667
|
-
printf '%s\n' "$content" > "$file"
|
|
668
|
-
echo "captured golden: $file"
|
|
669
|
-
return
|
|
670
|
-
fi
|
|
671
|
-
if [[ ! -f "$file" ]]; then
|
|
672
|
-
echo "FAIL: golden missing — $file (run: SOMI_GOLDEN_MODE=capture bash tests/scripts/run.sh)" >&2
|
|
673
|
-
failures=$((failures + 1))
|
|
674
|
-
return
|
|
675
|
-
fi
|
|
676
|
-
if ! diff -u "$file" <(printf '%s\n' "$content") >&2; then
|
|
677
|
-
echo "FAIL: golden mismatch — $file" >&2
|
|
678
|
-
failures=$((failures + 1))
|
|
679
|
-
fi
|
|
680
|
-
}
|
|
681
|
-
golden_compare "$GOLDEN_DIR/somi-loop.json" "$(printf '%s\n' "${LOOP_GOLDEN_CASES[@]}" | jq -s '.')"
|
|
682
|
-
golden_compare "$GOLDEN_DIR/somi-findings.json" "$(printf '%s\n' "${FINDINGS_GOLDEN_CASES[@]}" | jq -s '.')"
|
|
683
|
-
|
|
684
|
-
# --- summary --------------------------------------------------------------------
|
|
685
|
-
if (( failures > 0 )); then
|
|
686
|
-
echo "script tests: $failures of $total checks FAILED" >&2
|
|
687
|
-
exit 1
|
|
688
|
-
fi
|
|
689
|
-
echo "script tests: all $total checks passed."
|