@warpgogol/forge 9.5.0 → 9.6.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/CHANGELOG.md +18 -0
- package/README.md +30 -0
- package/README.uk.md +30 -0
- package/bin/cli.ts +19 -50
- package/dist/bin/cli.js +18 -43
- package/dist/bin/cli.js.map +1 -1
- package/dist/os/codebase/codebase.module.d.ts +3 -0
- package/dist/os/codebase/codebase.module.d.ts.map +1 -0
- package/dist/os/codebase/codebase.module.js +53 -0
- package/dist/os/codebase/codebase.module.js.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts +15 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.js +97 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure.d.ts +22 -0
- package/dist/os/codebase/handlers/codebase-measure.d.ts.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure.js +435 -0
- package/dist/os/codebase/handlers/codebase-measure.js.map +1 -0
- package/dist/os/codebase/index.d.ts +4 -0
- package/dist/os/codebase/index.d.ts.map +1 -0
- package/dist/os/codebase/index.js +13 -0
- package/dist/os/codebase/index.js.map +1 -0
- package/dist/os/codebase/types.d.ts +35 -0
- package/dist/os/codebase/types.d.ts.map +1 -0
- package/dist/os/codebase/types.js +17 -0
- package/dist/os/codebase/types.js.map +1 -0
- package/dist/os/core/handlers/package-health.d.ts +6 -4
- package/dist/os/core/handlers/package-health.d.ts.map +1 -1
- package/dist/os/core/handlers/package-health.js +15 -20
- package/dist/os/core/handlers/package-health.js.map +1 -1
- package/dist/os/correctness/anchors.d.ts +24 -0
- package/dist/os/correctness/anchors.d.ts.map +1 -0
- package/dist/os/correctness/anchors.js +156 -0
- package/dist/os/correctness/anchors.js.map +1 -0
- package/dist/os/correctness/audit/bindings-verify-substance.d.ts +7 -0
- package/dist/os/correctness/audit/bindings-verify-substance.d.ts.map +1 -0
- package/dist/os/correctness/audit/bindings-verify-substance.js +145 -0
- package/dist/os/correctness/audit/bindings-verify-substance.js.map +1 -0
- package/dist/os/correctness/audit/differential.d.ts +7 -0
- package/dist/os/correctness/audit/differential.d.ts.map +1 -0
- package/dist/os/correctness/audit/differential.js +105 -0
- package/dist/os/correctness/audit/differential.js.map +1 -0
- package/dist/os/correctness/audit/ledger-orphans.d.ts +6 -0
- package/dist/os/correctness/audit/ledger-orphans.d.ts.map +1 -0
- package/dist/os/correctness/audit/ledger-orphans.js +71 -0
- package/dist/os/correctness/audit/ledger-orphans.js.map +1 -0
- package/dist/os/correctness/audit/ledger.d.ts +29 -0
- package/dist/os/correctness/audit/ledger.d.ts.map +1 -0
- package/dist/os/correctness/audit/ledger.js +72 -0
- package/dist/os/correctness/audit/ledger.js.map +1 -0
- package/dist/os/correctness/audit/run.d.ts +27 -0
- package/dist/os/correctness/audit/run.d.ts.map +1 -0
- package/dist/os/correctness/audit/run.js +184 -0
- package/dist/os/correctness/audit/run.js.map +1 -0
- package/dist/os/correctness/audit/schema-db.d.ts +32 -0
- package/dist/os/correctness/audit/schema-db.d.ts.map +1 -0
- package/dist/os/correctness/audit/schema-db.js +166 -0
- package/dist/os/correctness/audit/schema-db.js.map +1 -0
- package/dist/os/correctness/audit/snapshot.d.ts +34 -0
- package/dist/os/correctness/audit/snapshot.d.ts.map +1 -0
- package/dist/os/correctness/audit/snapshot.js +190 -0
- package/dist/os/correctness/audit/snapshot.js.map +1 -0
- package/dist/os/correctness/audit/sql-scanner.d.ts +28 -0
- package/dist/os/correctness/audit/sql-scanner.d.ts.map +1 -0
- package/dist/os/correctness/audit/sql-scanner.js +279 -0
- package/dist/os/correctness/audit/sql-scanner.js.map +1 -0
- package/dist/os/correctness/audit/sql-schema-conform.d.ts +17 -0
- package/dist/os/correctness/audit/sql-schema-conform.d.ts.map +1 -0
- package/dist/os/correctness/audit/sql-schema-conform.js +163 -0
- package/dist/os/correctness/audit/sql-schema-conform.js.map +1 -0
- package/dist/os/correctness/audit/state-transitions-coverage.d.ts +19 -0
- package/dist/os/correctness/audit/state-transitions-coverage.d.ts.map +1 -0
- package/dist/os/correctness/audit/state-transitions-coverage.js +263 -0
- package/dist/os/correctness/audit/state-transitions-coverage.js.map +1 -0
- package/dist/os/correctness/audit/tests/git-fixture.d.ts +15 -0
- package/dist/os/correctness/audit/tests/git-fixture.d.ts.map +1 -0
- package/dist/os/correctness/audit/tests/git-fixture.js +85 -0
- package/dist/os/correctness/audit/tests/git-fixture.js.map +1 -0
- package/dist/os/correctness/audit/types.d.ts +58 -0
- package/dist/os/correctness/audit/types.d.ts.map +1 -0
- package/dist/os/correctness/audit/types.js +34 -0
- package/dist/os/correctness/audit/types.js.map +1 -0
- package/dist/os/correctness/correctness.module.d.ts +3 -0
- package/dist/os/correctness/correctness.module.d.ts.map +1 -0
- package/dist/os/correctness/correctness.module.js +173 -0
- package/dist/os/correctness/correctness.module.js.map +1 -0
- package/dist/os/correctness/gate/frozen.d.ts +52 -0
- package/dist/os/correctness/gate/frozen.d.ts.map +1 -0
- package/dist/os/correctness/gate/frozen.js +322 -0
- package/dist/os/correctness/gate/frozen.js.map +1 -0
- package/dist/os/correctness/gate/origin.d.ts +28 -0
- package/dist/os/correctness/gate/origin.d.ts.map +1 -0
- package/dist/os/correctness/gate/origin.js +139 -0
- package/dist/os/correctness/gate/origin.js.map +1 -0
- package/dist/os/correctness/gate/repo.d.ts +25 -0
- package/dist/os/correctness/gate/repo.d.ts.map +1 -0
- package/dist/os/correctness/gate/repo.js +88 -0
- package/dist/os/correctness/gate/repo.js.map +1 -0
- package/dist/os/correctness/gate/run.d.ts +22 -0
- package/dist/os/correctness/gate/run.d.ts.map +1 -0
- package/dist/os/correctness/gate/run.js +430 -0
- package/dist/os/correctness/gate/run.js.map +1 -0
- package/dist/os/correctness/gate/runner.d.ts +18 -0
- package/dist/os/correctness/gate/runner.d.ts.map +1 -0
- package/dist/os/correctness/gate/runner.js +123 -0
- package/dist/os/correctness/gate/runner.js.map +1 -0
- package/dist/os/correctness/gate/tests/gate-fixture.d.ts +36 -0
- package/dist/os/correctness/gate/tests/gate-fixture.d.ts.map +1 -0
- package/dist/os/correctness/gate/tests/gate-fixture.js +153 -0
- package/dist/os/correctness/gate/tests/gate-fixture.js.map +1 -0
- package/dist/os/correctness/gate/types.d.ts +102 -0
- package/dist/os/correctness/gate/types.d.ts.map +1 -0
- package/dist/os/correctness/gate/types.js +64 -0
- package/dist/os/correctness/gate/types.js.map +1 -0
- package/dist/os/correctness/handlers/audit.d.ts +4 -0
- package/dist/os/correctness/handlers/audit.d.ts.map +1 -0
- package/dist/os/correctness/handlers/audit.js +95 -0
- package/dist/os/correctness/handlers/audit.js.map +1 -0
- package/dist/os/correctness/handlers/gate.d.ts +4 -0
- package/dist/os/correctness/handlers/gate.d.ts.map +1 -0
- package/dist/os/correctness/handlers/gate.js +62 -0
- package/dist/os/correctness/handlers/gate.js.map +1 -0
- package/dist/os/correctness/handlers/validate.d.ts +19 -0
- package/dist/os/correctness/handlers/validate.d.ts.map +1 -0
- package/dist/os/correctness/handlers/validate.js +367 -0
- package/dist/os/correctness/handlers/validate.js.map +1 -0
- package/dist/os/correctness/index.d.ts +8 -0
- package/dist/os/correctness/index.d.ts.map +1 -0
- package/dist/os/correctness/index.js +23 -0
- package/dist/os/correctness/index.js.map +1 -0
- package/dist/os/correctness/manifest-schema.d.ts +155 -0
- package/dist/os/correctness/manifest-schema.d.ts.map +1 -0
- package/dist/os/correctness/manifest-schema.js +110 -0
- package/dist/os/correctness/manifest-schema.js.map +1 -0
- package/dist/os/correctness/references.d.ts +22 -0
- package/dist/os/correctness/references.d.ts.map +1 -0
- package/dist/os/correctness/references.js +129 -0
- package/dist/os/correctness/references.js.map +1 -0
- package/dist/os/correctness/tests/fixture-workspace.d.ts +23 -0
- package/dist/os/correctness/tests/fixture-workspace.d.ts.map +1 -0
- package/dist/os/correctness/tests/fixture-workspace.js +104 -0
- package/dist/os/correctness/tests/fixture-workspace.js.map +1 -0
- package/dist/os/correctness/workspace.d.ts +32 -0
- package/dist/os/correctness/workspace.d.ts.map +1 -0
- package/dist/os/correctness/workspace.js +147 -0
- package/dist/os/correctness/workspace.js.map +1 -0
- package/dist/os/flow/correctness-step.d.ts +19 -0
- package/dist/os/flow/correctness-step.d.ts.map +1 -0
- package/dist/os/flow/correctness-step.js +133 -0
- package/dist/os/flow/correctness-step.js.map +1 -0
- package/dist/os/flow/digest.d.ts +18 -0
- package/dist/os/flow/digest.d.ts.map +1 -1
- package/dist/os/flow/digest.js +28 -1
- package/dist/os/flow/digest.js.map +1 -1
- package/dist/os/flow/flow.module.d.ts.map +1 -1
- package/dist/os/flow/flow.module.js +17 -3
- package/dist/os/flow/flow.module.js.map +1 -1
- package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-digest.js +11 -1
- package/dist/os/flow/handlers/flow-digest.js.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.d.ts +11 -0
- package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.js +90 -5
- package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
- package/dist/os/flow/post-rebase-regen.d.ts +33 -0
- package/dist/os/flow/post-rebase-regen.d.ts.map +1 -0
- package/dist/os/flow/post-rebase-regen.js +120 -0
- package/dist/os/flow/post-rebase-regen.js.map +1 -0
- package/dist/os/flow/preflight.d.ts.map +1 -1
- package/dist/os/flow/preflight.js +11 -15
- package/dist/os/flow/preflight.js.map +1 -1
- package/dist/os/flow/publish.d.ts.map +1 -1
- package/dist/os/flow/publish.js +23 -4
- package/dist/os/flow/publish.js.map +1 -1
- package/dist/os/flow/registry.d.ts +4 -4
- package/dist/os/flow/tests/helpers.d.ts +9 -1
- package/dist/os/flow/tests/helpers.d.ts.map +1 -1
- package/dist/os/flow/tests/helpers.js +36 -2
- package/dist/os/flow/tests/helpers.js.map +1 -1
- package/dist/os/friction/types.d.ts +2 -2
- package/dist/os/gate-run/status.d.ts +12 -0
- package/dist/os/gate-run/status.d.ts.map +1 -1
- package/dist/os/gate-run/status.js +24 -3
- package/dist/os/gate-run/status.js.map +1 -1
- package/dist/os/program/schemas.d.ts +3 -3
- package/dist/os/queue/types.d.ts +2 -2
- package/dist/os/rfc/handlers/implement-stamp-promotes.d.ts +8 -0
- package/dist/os/rfc/handlers/implement-stamp-promotes.d.ts.map +1 -0
- package/dist/os/rfc/handlers/implement-stamp-promotes.js +65 -0
- package/dist/os/rfc/handlers/implement-stamp-promotes.js.map +1 -0
- package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.js +15 -2
- package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
- package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
- package/dist/os/rfc/handlers/validate-rules.js +26 -5
- package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
- package/dist/os/rfc/rfc.module.d.ts.map +1 -1
- package/dist/os/rfc/rfc.module.js +18 -6
- package/dist/os/rfc/rfc.module.js.map +1 -1
- package/dist/os/rfc/types.d.ts +12 -3
- package/dist/os/rfc/types.d.ts.map +1 -1
- package/dist/os/rfc/types.js +5 -2
- package/dist/os/rfc/types.js.map +1 -1
- package/dist/os/rfc/verify-workspace.d.ts +12 -0
- package/dist/os/rfc/verify-workspace.d.ts.map +1 -1
- package/dist/os/rfc/verify-workspace.js +155 -0
- package/dist/os/rfc/verify-workspace.js.map +1 -1
- package/dist/os/system/task-schemas.d.ts +1 -1
- package/dist/os/system/tests/helpers.d.ts.map +1 -1
- package/dist/os/system/tests/helpers.js +6 -1
- package/dist/os/system/tests/helpers.js.map +1 -1
- package/dist/os/werkstatt/handlers/schema.d.ts +1 -1
- package/dist/src/command-modules.d.ts +4 -0
- package/dist/src/command-modules.d.ts.map +1 -0
- package/dist/src/command-modules.js +42 -0
- package/dist/src/command-modules.js.map +1 -0
- package/dist/src/config/forge-config.d.ts +16 -1
- package/dist/src/config/forge-config.d.ts.map +1 -1
- package/dist/src/config/forge-config.js +27 -11
- package/dist/src/config/forge-config.js.map +1 -1
- package/dist/src/correctness/index.d.ts +32 -0
- package/dist/src/correctness/index.d.ts.map +1 -0
- package/dist/src/correctness/index.js +157 -0
- package/dist/src/correctness/index.js.map +1 -0
- package/dist/src/correctness/schema-hash.d.ts +15 -0
- package/dist/src/correctness/schema-hash.d.ts.map +1 -0
- package/dist/src/correctness/schema-hash.js +44 -0
- package/dist/src/correctness/schema-hash.js.map +1 -0
- package/dist/src/knowledge/schema.d.ts +1 -1
- package/dist/src/onboarding/agents-generate.d.ts.map +1 -1
- package/dist/src/onboarding/agents-generate.js +20 -3
- package/dist/src/onboarding/agents-generate.js.map +1 -1
- package/dist/src/onboarding/create.d.ts +7 -0
- package/dist/src/onboarding/create.d.ts.map +1 -1
- package/dist/src/onboarding/create.js +62 -9
- package/dist/src/onboarding/create.js.map +1 -1
- package/docs/reference/correctness-audit.md +91 -0
- package/docs/reference/correctness-gate.md +102 -0
- package/docs/reference/correctness-manifest.md +142 -0
- package/docs/reference/forge-yaml.md +15 -0
- package/os/codebase/codebase.module.ts +57 -0
- package/os/codebase/handlers/codebase-measure-symbols.ts +131 -0
- package/os/codebase/handlers/codebase-measure.ts +503 -0
- package/os/codebase/index.ts +21 -0
- package/os/codebase/types.ts +55 -0
- package/os/core/handlers/package-health.test.ts +24 -2
- package/os/core/handlers/package-health.ts +16 -19
- package/os/correctness/anchors.ts +182 -0
- package/os/correctness/audit/bindings-verify-substance.test.ts +79 -0
- package/os/correctness/audit/bindings-verify-substance.ts +155 -0
- package/os/correctness/audit/differential.test.ts +113 -0
- package/os/correctness/audit/differential.ts +131 -0
- package/os/correctness/audit/ledger-orphans.test.ts +96 -0
- package/os/correctness/audit/ledger-orphans.ts +84 -0
- package/os/correctness/audit/ledger.test.ts +65 -0
- package/os/correctness/audit/ledger.ts +103 -0
- package/os/correctness/audit/run.ts +220 -0
- package/os/correctness/audit/schema-db.ts +208 -0
- package/os/correctness/audit/snapshot.ts +211 -0
- package/os/correctness/audit/sql-scanner.test.ts +84 -0
- package/os/correctness/audit/sql-scanner.ts +289 -0
- package/os/correctness/audit/sql-schema-conform.test.ts +170 -0
- package/os/correctness/audit/sql-schema-conform.ts +178 -0
- package/os/correctness/audit/state-transitions-coverage.test.ts +141 -0
- package/os/correctness/audit/state-transitions-coverage.ts +271 -0
- package/os/correctness/audit/tests/git-fixture.ts +98 -0
- package/os/correctness/audit/types.ts +91 -0
- package/os/correctness/correctness-capture.test.ts +107 -0
- package/os/correctness/correctness-chain.test.ts +232 -0
- package/os/correctness/correctness-coverage.test.ts +86 -0
- package/os/correctness/correctness-mode.test.ts +108 -0
- package/os/correctness/correctness-substrate.test.ts +64 -0
- package/os/correctness/correctness.module.ts +182 -0
- package/os/correctness/gate/anchor-events.test.ts +77 -0
- package/os/correctness/gate/freeze-coverage.test.ts +218 -0
- package/os/correctness/gate/freeze-diff.test.ts +110 -0
- package/os/correctness/gate/frozen.ts +399 -0
- package/os/correctness/gate/gate-mode.test.ts +76 -0
- package/os/correctness/gate/hardening.test.ts +175 -0
- package/os/correctness/gate/oracle-edit.test.ts +83 -0
- package/os/correctness/gate/oracle-origin.test.ts +142 -0
- package/os/correctness/gate/origin.ts +175 -0
- package/os/correctness/gate/repo.ts +102 -0
- package/os/correctness/gate/run.ts +547 -0
- package/os/correctness/gate/runner.ts +136 -0
- package/os/correctness/gate/substrate-attestation.test.ts +71 -0
- package/os/correctness/gate/tests/gate-fixture.ts +205 -0
- package/os/correctness/gate/tier-high.test.ts +92 -0
- package/os/correctness/gate/types.ts +144 -0
- package/os/correctness/handlers/audit.ts +107 -0
- package/os/correctness/handlers/gate.ts +75 -0
- package/os/correctness/handlers/validate.ts +514 -0
- package/os/correctness/index.ts +24 -0
- package/os/correctness/manifest-schema.ts +174 -0
- package/os/correctness/references.ts +143 -0
- package/os/correctness/tests/fixture-workspace.ts +119 -0
- package/os/correctness/workspace.ts +167 -0
- package/os/flow/correctness-step.ts +166 -0
- package/os/flow/digest.ts +40 -1
- package/os/flow/flow.module.ts +18 -3
- package/os/flow/handlers/flow-digest.ts +11 -1
- package/os/flow/handlers/flow-integrate.ts +117 -5
- package/os/flow/post-rebase-regen.ts +170 -0
- package/os/flow/preflight.ts +11 -19
- package/os/flow/publish.ts +23 -4
- package/os/flow/tests/flow-detachable.test.ts +31 -0
- package/os/flow/tests/flow-digest-correctness-trail.test.ts +55 -0
- package/os/flow/tests/flow-integrate-correctness-gate.test.ts +275 -0
- package/os/flow/tests/flow-integrate.post-rebase-regen.test.ts +234 -0
- package/os/flow/tests/flow-integrate.test.ts +10 -9
- package/os/flow/tests/helpers.ts +45 -24
- package/os/gate-run/status.ts +36 -3
- package/os/gate-run/tests/gate-run-status.test.ts +114 -0
- package/os/rfc/handlers/implement-stamp-promotes.test.ts +214 -0
- package/os/rfc/handlers/implement-stamp-promotes.ts +79 -0
- package/os/rfc/handlers/implement-stamp.ts +16 -2
- package/os/rfc/handlers/validate-rules.ts +43 -5
- package/os/rfc/rfc.module.ts +19 -6
- package/os/rfc/types.ts +16 -2
- package/os/rfc/verify-workspace-manifest.test.ts +55 -0
- package/os/rfc/verify-workspace.ts +167 -0
- package/os/system/tests/helpers.ts +6 -1
- package/package.json +41 -1
- package/profiles/typescript.yaml +16 -0
- package/skills/_shared/agent-operating-model.md +4 -0
- package/skills/fo/fo-idea-audit/SKILL.md +4 -0
- package/skills/fo/fo-idea-create-rfc/SKILL.md +6 -2
- package/skills/fo/fo-idea-implement/SKILL.md +8 -2
- package/skills/fo/fo-review/SKILL.md +16 -2
- package/src/command-modules.ts +62 -0
- package/src/config/forge-config.ts +37 -11
- package/src/correctness/index.ts +192 -0
- package/src/correctness/schema-hash.ts +59 -0
- package/src/onboarding/agents-generate.ts +20 -3
- package/src/onboarding/create.ts +59 -9
- package/src/tests/agents-generate-detach.test.ts +126 -0
- package/src/tests/codebase-measure-rfc-1581.test.ts +260 -0
- package/src/tests/command-modules.test.ts +34 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
RFC-1581: tests for codebase.measure — exclusion contour, category
|
|
5
|
+
classification, line metrics, AST symbol counts, honest degradation,
|
|
6
|
+
binary files, read-only default and --out snapshot writing.
|
|
7
|
+
</purpose>
|
|
8
|
+
</MODULE_CONTRACT>
|
|
9
|
+
<CHANGE_SUMMARY>
|
|
10
|
+
<item>RFC-1581: initial test coverage.</item>
|
|
11
|
+
<item>RFC-1581: add codebase.measure project-scale measurement command</item>
|
|
12
|
+
<item>RFC-1581: apply REVIEW-CODE-2026-11-13-01 — contract alignment, repo-root anchor, publishConfig exports</item>
|
|
13
|
+
</CHANGE_SUMMARY>
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { execFileSync } from "node:child_process";
|
|
17
|
+
import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
|
|
18
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
19
|
+
import { createRequire } from "node:module";
|
|
20
|
+
import { tmpdir } from "node:os";
|
|
21
|
+
import { basename, dirname, join } from "node:path";
|
|
22
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
23
|
+
|
|
24
|
+
import { runCodebaseMeasure } from "../../os/codebase/handlers/codebase-measure.ts";
|
|
25
|
+
import type { CodebaseMeasure } from "../../os/codebase/types.ts";
|
|
26
|
+
import type { ForgeCommandInput, ForgeRuntimeContext, ForgeLogger } from "../../src/types.ts";
|
|
27
|
+
|
|
28
|
+
const noopLogger: ForgeLogger = {
|
|
29
|
+
section: () => {},
|
|
30
|
+
info: () => {},
|
|
31
|
+
warn: () => {},
|
|
32
|
+
error: () => {},
|
|
33
|
+
success: () => {},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function makeContext(workspaceRoot: string): ForgeRuntimeContext {
|
|
37
|
+
return { workspaceRoot, logger: noopLogger, dryRun: false, outputFormat: "json" };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const NO_FLAGS: ForgeCommandInput = { argv: [], flags: {} };
|
|
41
|
+
|
|
42
|
+
function gitInit(root: string): void {
|
|
43
|
+
execFileSync("git", ["init", "--quiet"], { cwd: root });
|
|
44
|
+
execFileSync("git", ["config", "user.email", "test@test.com"], { cwd: root });
|
|
45
|
+
execFileSync("git", ["config", "user.name", "Test"], { cwd: root });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function add(root: string, rel: string, content: string | Buffer): Promise<void> {
|
|
49
|
+
const abs = join(root, rel);
|
|
50
|
+
await mkdir(dirname(abs), { recursive: true });
|
|
51
|
+
await writeFile(abs, content);
|
|
52
|
+
execFileSync("git", ["add", rel], { cwd: root });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function addUntracked(root: string, rel: string, content: string): Promise<void> {
|
|
56
|
+
const abs = join(root, rel);
|
|
57
|
+
await mkdir(dirname(abs), { recursive: true });
|
|
58
|
+
await writeFile(abs, content);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const testRequire = createRequire(import.meta.url);
|
|
62
|
+
|
|
63
|
+
/** Give the fixture a resolvable typescript (the pass resolves from workspaceRoot). */
|
|
64
|
+
async function linkTypescript(root: string): Promise<void> {
|
|
65
|
+
const tsPkg = dirname(testRequire.resolve("typescript/package.json"));
|
|
66
|
+
await mkdir(join(root, "node_modules"), { recursive: true });
|
|
67
|
+
await symlink(tsPkg, join(root, "node_modules", "typescript"), "dir");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function measure(
|
|
71
|
+
root: string,
|
|
72
|
+
flags: Record<string, string | boolean> = {},
|
|
73
|
+
): Promise<{ data: CodebaseMeasure; exitCode?: number }> {
|
|
74
|
+
const res = await runCodebaseMeasure({ argv: [], flags }, makeContext(root));
|
|
75
|
+
return { data: res.data as CodebaseMeasure, exitCode: res.exitCode };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
describe("RFC-1581: codebase.measure", () => {
|
|
79
|
+
let root: string;
|
|
80
|
+
|
|
81
|
+
beforeEach(async () => {
|
|
82
|
+
root = await mkdtemp(join(tmpdir(), "codebase-measure-XXXXXX-"));
|
|
83
|
+
gitInit(root);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
afterEach(async () => {
|
|
87
|
+
await rm(root, { recursive: true, force: true });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("AC-1: counts code/comment/blank lines on the tracked set", async () => {
|
|
91
|
+
await add(root, "src/a.ts", "// c\nconst x = 1;\n\nconst y = 2;\n");
|
|
92
|
+
const { data, exitCode } = await measure(root);
|
|
93
|
+
expect(exitCode).toBe(0);
|
|
94
|
+
expect(data.status).toBe("ok");
|
|
95
|
+
expect(data.totals.code.files).toBe(1);
|
|
96
|
+
expect(data.totals.code.code).toBe(2);
|
|
97
|
+
const ts = data.languages.find((l) => l.language === "TypeScript");
|
|
98
|
+
expect(ts).toBeDefined();
|
|
99
|
+
expect(ts!.comments).toBe(1);
|
|
100
|
+
expect(ts!.blanks).toBe(1);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("AC-4: excluded paths and untracked files never enter the measurement", async () => {
|
|
104
|
+
await add(root, "src/keep.ts", "const a = 1;\n");
|
|
105
|
+
await add(root, ".agents/skills/x/SKILL.md", "# twin\n");
|
|
106
|
+
await add(root, "missions/m1/a.ts", "const m = 1;\n");
|
|
107
|
+
await add(root, "docs/specs/spec.md", "# spec\n");
|
|
108
|
+
await add(root, "docs/audits/old.md", "# audit\n");
|
|
109
|
+
await add(root, "dist/bundle.js", "var b;\n");
|
|
110
|
+
await add(root, "docs/metrics/m.yaml", "a: 1\n");
|
|
111
|
+
await addUntracked(root, "src/untracked.ts", "const u = 1;\n");
|
|
112
|
+
const { data } = await measure(root);
|
|
113
|
+
expect(data.totals.code.files).toBe(1);
|
|
114
|
+
expect(data.totals.code.code).toBe(1);
|
|
115
|
+
expect(data.languages.map((l) => l.language)).toEqual(["TypeScript"]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("AC-5: categories are exactly code/tests/docs/generated, first-match wins", async () => {
|
|
119
|
+
await add(root, "src/impl.ts", "const i = 1;\n");
|
|
120
|
+
await add(root, "src/x.test.ts", "const t = 1;\n");
|
|
121
|
+
await add(root, "tests/e2e.ts", "const e = 1;\n");
|
|
122
|
+
await add(root, "README.md", "# hi\n");
|
|
123
|
+
await add(root, "docs/cfg.yaml", "a: 1\n");
|
|
124
|
+
await add(root, "LICENSE", "MIT\n");
|
|
125
|
+
await add(root, "docs/eco.generated.yaml", "a: 1\n");
|
|
126
|
+
const { data } = await measure(root);
|
|
127
|
+
expect(Object.keys(data.totals).sort()).toEqual(["code", "docs", "generated", "tests"]);
|
|
128
|
+
expect(data.totals.code.files).toBe(1);
|
|
129
|
+
expect(data.totals.tests.files).toBe(2);
|
|
130
|
+
expect(data.totals.docs.files).toBe(3);
|
|
131
|
+
expect(data.totals.generated.files).toBe(1);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("AC-6: AST-derived symbol counts for the TS family", async () => {
|
|
135
|
+
await linkTypescript(root);
|
|
136
|
+
await add(
|
|
137
|
+
root,
|
|
138
|
+
"src/k.ts",
|
|
139
|
+
"class K {\n m() {}\n}\nfunction f() {}\nconst g = () => 1;\nconst h = function () {};\n",
|
|
140
|
+
);
|
|
141
|
+
const { data } = await measure(root);
|
|
142
|
+
const ts = data.languages.find((l) => l.language === "TypeScript");
|
|
143
|
+
expect(ts!.symbols).toBeDefined();
|
|
144
|
+
expect(ts!.symbols!.classes).toBe(1);
|
|
145
|
+
expect(ts!.symbols!.methods).toBe(1);
|
|
146
|
+
expect(ts!.symbols!.functions).toBe(3); // f + arrow g + function-expression h
|
|
147
|
+
expect(data.symbolsSkipped).toEqual([]);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("AC-6: .astro counts markup lines; frontmatter feeds the symbol pass", async () => {
|
|
151
|
+
await linkTypescript(root);
|
|
152
|
+
await add(root, "src/P.astro", "---\nconst x = 1;\nfunction go() {}\n---\n<div>hi</div>\n");
|
|
153
|
+
const { data } = await measure(root);
|
|
154
|
+
const astro = data.languages.find((l) => l.language === "Astro");
|
|
155
|
+
expect(astro).toBeDefined();
|
|
156
|
+
expect(astro!.files).toBe(1);
|
|
157
|
+
expect(astro!.symbols!.functions).toBe(1);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("AC-3: missing typescript degrades to lines-only with an explicit skip", async () => {
|
|
161
|
+
await add(root, "src/a.ts", "class A {}\n");
|
|
162
|
+
const { data, exitCode } = await measure(root);
|
|
163
|
+
expect(exitCode).toBe(0);
|
|
164
|
+
expect(data.symbolsSkipped).toContain("typescript-unavailable");
|
|
165
|
+
const ts = data.languages.find((l) => l.language === "TypeScript");
|
|
166
|
+
expect(ts!.code).toBe(1);
|
|
167
|
+
expect(ts!.symbols).toBeUndefined();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("AC-2/AC-10: fails with required nextSteps outside a git repository", async () => {
|
|
171
|
+
const bare = await mkdtemp(join(tmpdir(), "codebase-nogit-XXXXXX-"));
|
|
172
|
+
try {
|
|
173
|
+
const res = await runCodebaseMeasure(NO_FLAGS, makeContext(bare));
|
|
174
|
+
expect(res.exitCode).toBe(1);
|
|
175
|
+
expect(res.summary).toContain("[codebase.measure]");
|
|
176
|
+
expect(res.nextSteps?.some((s) => s.kind === "required")).toBe(true);
|
|
177
|
+
} finally {
|
|
178
|
+
await rm(bare, { recursive: true, force: true });
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("binary files count toward files but contribute zero lines", async () => {
|
|
183
|
+
await add(root, "src/a.ts", "const x = 1;\n");
|
|
184
|
+
await add(root, "img/logo.png", Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x00, 0x01]));
|
|
185
|
+
await add(root, "img/logo.generated.png", Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x00, 0x01]));
|
|
186
|
+
const { data } = await measure(root);
|
|
187
|
+
expect(data.binaryFiles).toBe(2);
|
|
188
|
+
expect(data.totals.code.files).toBe(2); // a.ts + logo.png (name rules apply)
|
|
189
|
+
expect(data.totals.generated.files).toBe(1); // logo.generated.png — name rule without content
|
|
190
|
+
expect(data.totals.code.code).toBe(1);
|
|
191
|
+
expect(data.languages).toHaveLength(1);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("lockfiles count as generated bookkeeping mass, never as code", async () => {
|
|
195
|
+
await add(root, "pnpm-lock.yaml", "lockfileVersion: '9.0'\n");
|
|
196
|
+
await add(root, "src/a.ts", "const x = 1;\n");
|
|
197
|
+
const { data } = await measure(root);
|
|
198
|
+
expect(data.totals.generated.files).toBe(1);
|
|
199
|
+
expect(data.totals.code.files).toBe(1);
|
|
200
|
+
expect(data.totals.code.code).toBe(1);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("AC-1: contract keys — repo, exclusions, measuredAt present in data", async () => {
|
|
204
|
+
await add(root, "missions/m1/a.ts", "const m = 1;\n");
|
|
205
|
+
await add(root, "src/a.ts", "const x = 1;\n");
|
|
206
|
+
const { data } = await measure(root);
|
|
207
|
+
expect(data.repo).toBe(basename(root));
|
|
208
|
+
expect(data.measuredAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
209
|
+
expect(data.exclusions).toContain("dir:missions/");
|
|
210
|
+
expect(data.exclusions).not.toContain("dir:docs/specs/");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("anchors on the repo root — identical measurement from a subdirectory", async () => {
|
|
214
|
+
await add(root, "src/a.ts", "const x = 1;\n");
|
|
215
|
+
await add(root, "docs/guide.md", "# g\n");
|
|
216
|
+
const sub = join(root, "src");
|
|
217
|
+
const res = await runCodebaseMeasure(NO_FLAGS, makeContext(sub));
|
|
218
|
+
expect(res.exitCode).toBe(0);
|
|
219
|
+
expect(res.data!.totals.code.files).toBe(1);
|
|
220
|
+
expect(res.data!.totals.docs.files).toBe(1);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("empty repository exits 0 with zeroed measures", async () => {
|
|
224
|
+
const { data, exitCode } = await measure(root);
|
|
225
|
+
expect(exitCode).toBe(0);
|
|
226
|
+
expect(data.totals.code).toEqual({ files: 0, code: 0 });
|
|
227
|
+
expect(data.languages).toEqual([]);
|
|
228
|
+
expect(data.topDirs).toEqual([]);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("AC-9: default invocation writes nothing; --out writes the snapshot", async () => {
|
|
232
|
+
await add(root, "src/a.ts", "const x = 1;\n");
|
|
233
|
+
const before = (dir: string): string[] =>
|
|
234
|
+
readdirSync(dir, { recursive: true })
|
|
235
|
+
.map(String)
|
|
236
|
+
.filter((f) => !f.startsWith(".git"));
|
|
237
|
+
const namesBefore = before(root);
|
|
238
|
+
await measure(root);
|
|
239
|
+
expect(before(root)).toEqual(namesBefore);
|
|
240
|
+
|
|
241
|
+
const { data, exitCode } = await measure(root, { out: "snap/snap.yaml" });
|
|
242
|
+
expect(exitCode).toBe(0);
|
|
243
|
+
expect(existsSync(join(root, "snap", "snap.yaml"))).toBe(true);
|
|
244
|
+
const snap = readFileSync(join(root, "snap", "snap.yaml"), "utf8");
|
|
245
|
+
expect(snap).toContain("codebase.measure");
|
|
246
|
+
expect(data.status).toBe("ok");
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("topDirs ranks directories by code lines, capped at 10", async () => {
|
|
250
|
+
for (let i = 0; i < 12; i++) {
|
|
251
|
+
await add(root, `pkg${i}/src/a.ts`, `const x${i} = ${i};\n`.repeat(i + 1));
|
|
252
|
+
}
|
|
253
|
+
const { data } = await measure(root);
|
|
254
|
+
expect(data.topDirs.length).toBe(10);
|
|
255
|
+
expect(data.topDirs[0]!.path).toBe("pkg11/src");
|
|
256
|
+
for (let i = 1; i < data.topDirs.length; i++) {
|
|
257
|
+
expect(data.topDirs[i]!.code).toBeLessThanOrEqual(data.topDirs[i - 1]!.code);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1573 review C-1 — loadForgeCommandModules() is the single forge command-module list: non-empty, every command name unique, and it carries the RFC-1568/RFC-1573 detachable set.</purpose>
|
|
4
|
+
<non-goals>
|
|
5
|
+
<item>No CLI dispatch — bin-entry tests own the executable surface.</item>
|
|
6
|
+
</non-goals>
|
|
7
|
+
</MODULE_CONTRACT>
|
|
8
|
+
*/
|
|
9
|
+
// Test-Reason: regression single-list drift between bin/cli.ts and agents-generate (RFC-1573 review C-1)
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
import { loadForgeCommandModules } from "../command-modules.ts";
|
|
12
|
+
|
|
13
|
+
describe("loadForgeCommandModules (RFC-1573)", () => {
|
|
14
|
+
it("returns modules with unique command names", async () => {
|
|
15
|
+
const names = (await loadForgeCommandModules()).flatMap((m) => m.commands.map((c) => c.name));
|
|
16
|
+
expect(names.length).toBeGreaterThan(0);
|
|
17
|
+
const dupes = names.filter((n, i) => names.indexOf(n) !== i);
|
|
18
|
+
expect(dupes, "duplicate forge command names would collide in buildRegistry()").toEqual([]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("carries the forge detachable set", async () => {
|
|
22
|
+
const detachable = (await loadForgeCommandModules())
|
|
23
|
+
.flatMap((m) => m.commands)
|
|
24
|
+
.filter((c) => c.detachable === true)
|
|
25
|
+
.map((c) => c.name)
|
|
26
|
+
.sort();
|
|
27
|
+
expect(detachable).toEqual([
|
|
28
|
+
"flow.backmerge",
|
|
29
|
+
"flow.cut",
|
|
30
|
+
"flow.integrate",
|
|
31
|
+
"rfc.implement.stamp",
|
|
32
|
+
]);
|
|
33
|
+
});
|
|
34
|
+
});
|