forgedock 1.55.1 → 1.57.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/bin/config-schema.mjs +1 -1
- package/bin/engine/outcome-codes.mjs +1 -0
- package/bin/engine/phases.mjs +4 -3
- package/bin/engine-cli.mjs +58 -10
- package/bin/forgedock.mjs +52 -3
- package/bin/gc.mjs +43 -6
- package/bin/help-text.mjs +3 -1
- package/bin/lean/batch-health.mjs +5 -1
- package/bin/lean/batch-health.test.mjs +7 -1
- package/bin/lean/batch.mjs +7 -2
- package/bin/lean/batch.test.mjs +45 -0
- package/bin/lean/conformance.e2e.test.mjs +3 -2
- package/bin/lean/conformance.mjs +88 -17
- package/bin/lean/conformance.test.mjs +98 -3
- package/bin/lean/decisions.mjs +86 -1
- package/bin/lean/decisions.test.mjs +21 -1
- package/bin/lean/depcache.mjs +124 -13
- package/bin/lean/depcache.test.mjs +121 -3
- package/bin/lean/design-gate.mjs +144 -0
- package/bin/lean/design-gate.test.mjs +169 -0
- package/bin/lean/effects-cap.test.mjs +17 -0
- package/bin/lean/effects.mjs +58 -13
- package/bin/lean/heavy.mjs +25 -8
- package/bin/lean/hostload.test.mjs +28 -0
- package/bin/lean/intake.mjs +97 -0
- package/bin/lean/intake.test.mjs +105 -0
- package/bin/lean/interfaces.mjs +181 -0
- package/bin/lean/interfaces.test.mjs +192 -0
- package/bin/lean/issuewatch-install.mjs +52 -12
- package/bin/lean/issuewatch-install.test.mjs +50 -0
- package/bin/lean/issuewatch-parity.mjs +12 -2
- package/bin/lean/issuewatch-parity.test.mjs +26 -0
- package/bin/lean/issuewatch-reconcile.mjs +29 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +21 -0
- package/bin/lean/issuewatch.mjs +34 -3
- package/bin/lean/issuewatch.test.mjs +49 -1
- package/bin/lean/lanecheck.test.mjs +15 -4
- package/bin/lean/lean.mjs +80 -25
- package/bin/lean/lean.test.mjs +149 -3
- package/bin/lean/orchestrate-blocked.test.mjs +18 -2
- package/bin/lean/orchestrate-owned.test.mjs +14 -5
- package/bin/lean/orchestrate.mjs +26 -4
- package/bin/lean/orphan-pr.mjs +125 -0
- package/bin/lean/orphan-pr.test.mjs +145 -0
- package/bin/lean/pagegate.mjs +35 -12
- package/bin/lean/pagegate.test.mjs +39 -1
- package/bin/lean/preflight.mjs +35 -1
- package/bin/lean/preflight.test.mjs +27 -1
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/reap.test.mjs +39 -0
- package/bin/lean/recovery.test.mjs +25 -0
- package/bin/lean/release-config.mjs +158 -0
- package/bin/lean/release-config.test.mjs +109 -0
- package/bin/lean/release-control.mjs +148 -0
- package/bin/lean/release-control.test.mjs +143 -0
- package/bin/lean/release-fence.mjs +50 -0
- package/bin/lean/release-fence.test.mjs +105 -0
- package/bin/lean/release-flakes.mjs +139 -0
- package/bin/lean/release-flakes.test.mjs +116 -0
- package/bin/lean/release-ledger.mjs +160 -0
- package/bin/lean/release-ledger.test.mjs +226 -0
- package/bin/lean/release-minutes.mjs +92 -0
- package/bin/lean/release-minutes.test.mjs +99 -0
- package/bin/lean/release-nightly.mjs +75 -0
- package/bin/lean/release-nightly.test.mjs +48 -0
- package/bin/lean/release-postmerge.mjs +45 -21
- package/bin/lean/release-review.e2e.test.mjs +1 -0
- package/bin/lean/release-review.mjs +54 -7
- package/bin/lean/release-review.test.mjs +76 -7
- package/bin/lean/release-unitmap.mjs +35 -0
- package/bin/lean/release-unitmap.test.mjs +41 -0
- package/bin/lean/release.mjs +177 -19
- package/bin/lean/release.test.mjs +80 -16
- package/bin/lean/render.mjs +3 -1
- package/bin/lean/run-issue-placement.test.mjs +82 -0
- package/bin/lean/sandbox-remote.mjs +16 -0
- package/bin/lean/schedd.mjs +1 -1
- package/bin/lean/seam.mjs +115 -0
- package/bin/lean/seam.test.mjs +118 -0
- package/bin/lean/selftest-journey.mjs +40 -2
- package/bin/lean/selftest-journey.test.mjs +43 -3
- package/bin/lean/statuscomment.mjs +168 -0
- package/bin/lean/statuscomment.test.mjs +133 -0
- package/bin/lean/ui-quality.mjs +57 -0
- package/bin/lean/ui-quality.test.mjs +55 -0
- package/bin/lean/visual-gate.test.mjs +63 -0
- package/bin/pool/agent.mjs +16 -2
- package/bin/pool/router.mjs +5 -1
- package/bin/review-staging.mjs +8 -5
- package/bin/stats/card.mjs +117 -0
- package/bin/stats/card.test.mjs +109 -0
- package/bin/stats/conformance-outcomes.test.mjs +2 -1
- package/bin/stats/depth.mjs +1 -1
- package/bin/stats/gh-retry.test.mjs +152 -0
- package/bin/stats/github-source.mjs +147 -14
- package/bin/stats/index.mjs +35 -2
- package/bin/stats/stats.test.mjs +31 -3
- package/bin/vendor/js-yaml/LICENSE +21 -0
- package/bin/vendor/js-yaml/PIN.md +7 -0
- package/bin/vendor/js-yaml/js-yaml.mjs +3851 -0
- package/commands/design-render-critique-loop.md +2 -0
- package/commands/design.md +2 -0
- package/commands/incident-response.md +4 -0
- package/commands/issue.md +1 -1
- package/commands/milestone.md +1 -1
- package/commands/pipeline-status.md +13 -0
- package/commands/review-pr-agents/frontend.md +1 -0
- package/commands/review-pr-staging.md +5 -0
- package/docs/CONFIG.md +75 -1
- package/docs/ISSUE-WATCH.md +7 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +10 -0
- package/docs/design/visual-gate.md +25 -0
- package/docs/eval/adversarial-bench.md +2 -2
- package/docs/eval/corpus/adversarial-v1.json +3 -3
- package/docs/site/start-a-new-project.md +7 -0
- package/docs/spec/forge-protocol-v1.md +31 -0
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/scripts/acceptance-red-green.sh +15 -1
- package/scripts/acceptance-red-green.test.sh +12 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +4 -1
- package/scripts/bootstrap-create.mjs +8 -2
- package/scripts/ci-local.test.sh +3 -3
- package/scripts/fixtures/ci-local/gha-dorny/.github/workflows/ci.yml +4 -0
- package/scripts/plan-validate-live.mjs +9 -6
- package/scripts/review-prepare.sh +7 -1
- package/scripts/review-roster.sh +5 -2
- package/scripts/review-roster.test.sh +9 -0
- package/scripts/visual-gate.mjs +64 -0
- package/templates/bootstrap/technical-spike.md +17 -0
- package/templates/contracts/seam-check.mjs +236 -0
|
@@ -10,9 +10,13 @@ jobs:
|
|
|
10
10
|
frontend: ${{ steps.filter.outputs.frontend }}
|
|
11
11
|
steps:
|
|
12
12
|
- uses: actions/checkout@v4
|
|
13
|
+
with:
|
|
14
|
+
fetch-depth: 0
|
|
13
15
|
- uses: dorny/paths-filter@v3
|
|
14
16
|
id: filter
|
|
15
17
|
with:
|
|
18
|
+
token: ''
|
|
19
|
+
base: ${{ github.base_ref }}
|
|
16
20
|
filters: |
|
|
17
21
|
backend:
|
|
18
22
|
- 'backend/**'
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { execFileSync } from "node:child_process";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
12
|
import { parseDependsOn, isTrustedComment } from "../bin/engine/phases.mjs";
|
|
13
|
+
import { mapLimit } from "../bin/lean/pmap.mjs";
|
|
13
14
|
import { parseState } from "../bin/engine/state.mjs";
|
|
14
15
|
|
|
15
16
|
/** Milestones in train order. Input: [{ title, number, due_on }]. */
|
|
@@ -102,13 +103,15 @@ export async function unmetDependencies({ issues, baseOf, gh, repo, isAncestor }
|
|
|
102
103
|
const r = repo ? ["-R", repo] : [];
|
|
103
104
|
const view = async (n, fields) => parse(await gh(["issue", "view", String(n), ...r, "--json", fields]));
|
|
104
105
|
const inBatch = new Set(issues);
|
|
105
|
-
const
|
|
106
|
-
|
|
106
|
+
const perIssue = [];
|
|
107
|
+
// #5592: bounded-concurrency reads (the gh calls were serial, starving admission on a loaded host); results keep issue order.
|
|
108
|
+
await mapLimit(issues, 6, async (n, idx) => {
|
|
109
|
+
const unmet = []; perIssue[idx] = unmet;
|
|
107
110
|
let rec;
|
|
108
111
|
try { rec = await view(n, "body,milestone"); } catch { rec = null; }
|
|
109
|
-
if (!rec || !rec.milestone)
|
|
112
|
+
if (!rec || !rec.milestone) return;
|
|
110
113
|
const base = await baseOf(n);
|
|
111
|
-
if (!base)
|
|
114
|
+
if (!base) return;
|
|
112
115
|
for (const dep of parseDependsOn(rec.body, n).filter((d) => !inBatch.has(d))) {
|
|
113
116
|
let why = null, sha = null;
|
|
114
117
|
try {
|
|
@@ -155,8 +158,8 @@ export async function unmetDependencies({ issues, baseOf, gh, repo, isAncestor }
|
|
|
155
158
|
} catch { why = "unreadable"; }
|
|
156
159
|
if (why) unmet.push({ issue: n, dep, base, why, sha, kind: sha ? "commit" : "other" });
|
|
157
160
|
}
|
|
158
|
-
}
|
|
159
|
-
return
|
|
161
|
+
});
|
|
162
|
+
return perIssue.flat();
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
const ghExec = async (args) => execFileSync("gh", args, { encoding: "utf8", maxBuffer: 100 * 1024 * 1024, timeout: 60000 });
|
|
@@ -98,6 +98,7 @@ if [ -n "$DELTA_FROM_OPT" ] && [ "$THOROUGH" = "true" ]; then echo "review-prepa
|
|
|
98
98
|
type forge_resolve >/dev/null 2>&1 || { setopt nonomatch 2>/dev/null || true; _SELF_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." 2>/dev/null && pwd -P)"; for _r in "$(cygpath -u "${FORGEDOCK_HOME:-}" 2>/dev/null || printf %s "${FORGEDOCK_HOME:-}")" "${CLAUDE_PLUGIN_ROOT:-}" "${FORGE_ROOT:-}" "${FORGE_HOME:-}" "$(readlink -f "$HOME/.claude/commands/work-on.md" 2>/dev/null | sed 's|/commands/work-on\.md$||')" "$(head -n 1 "${CODEX_HOME:-$HOME/.codex}/forge-home" 2>/dev/null)" "$HOME/.claude/plugins/marketplaces/forgedock" "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/plugins/cache/forgedock/forgedock/* "$HOME/.claude"/plugins/cache/forgedock/forgedock/* "$_SELF_ROOT"; do case "$_r" in /*) [ -f "$_r/scripts/lib/forge-resolve.sh" ] && { . "$_r/scripts/lib/forge-resolve.sh"; break; };; esac; done; type forge_resolve >/dev/null 2>&1 || forge_resolve() { :; }; }
|
|
99
99
|
|
|
100
100
|
ROSTER_SCRIPT=$(forge_resolve review-roster.sh)
|
|
101
|
+
VGATE_SCRIPT=$(forge_resolve visual-gate.mjs 2>/dev/null)
|
|
101
102
|
TRUSTED_SCRIPT=$(forge_resolve trusted-comments.sh)
|
|
102
103
|
# shellcheck disable=SC2034 # read by lib/review-delta-mode.sh (sourced below)
|
|
103
104
|
REVIEW_DELTA_SCRIPT=$(forge_resolve review-delta.sh)
|
|
@@ -425,10 +426,15 @@ SC="AUTH=$SCORE_AUTH BILLING=$SCORE_BILLING CONCURRENCY=$SCORE_CONCURRENCY DATAB
|
|
|
425
426
|
SPEC_CLI=false; [ -n "$TOP" ] && [ -f "$TOP/commands/review-pr-agents/spec-cli.md" ] && SPEC_CLI=true # existence only
|
|
426
427
|
SCRAPING_ON=false; [ -n "$DOMAIN_CONTEXT_SCRAPING" ] && SCRAPING_ON=true
|
|
427
428
|
DBC=false; printf '%s\n' "$DIFF" | grep -qE "docker-compose.*postgres|docker-compose.*redis|postgres.*command:|redis.*command:" && DBC=true
|
|
429
|
+
# forge#5330: a changed user-visible route under forge.yaml design.routes (scripts/visual-gate.mjs --list names one) adds the Frontend persona; unset or unresolved = false
|
|
430
|
+
DESIGN_ROUTES=false
|
|
431
|
+
if [ -n "$VGATE_SCRIPT" ] && [ -n "$TOP" ] && [ -f "$TOP/forge.yaml" ] && command -v node >/dev/null 2>&1; then
|
|
432
|
+
printf '%s\n' "$FILES" | node "$VGATE_SCRIPT" --root "$TOP" --files-file - --list 2>/dev/null | grep -q '"file"' && DESIGN_ROUTES=true
|
|
433
|
+
fi
|
|
428
434
|
ROSTER_OUT=""
|
|
429
435
|
[ -n "$ROSTER_SCRIPT" ] && ROSTER_OUT=$(printf '%s\n' "$FILES" | bash "$ROSTER_SCRIPT" --files-file - --scores "$SC" --changed-lines "$LINES" --changed-files "$NFILES" \
|
|
430
436
|
--fix-pr "$FIX_PR" --source-severity "$SRC_SEV" --source-domain "$SRC_DOM" --contract-flags "$CONTRACT_RISK_FLAGS" --churn "$CHURN_ESCALATION" --danger-zone "$DANGER" \
|
|
431
|
-
--thorough "$THOROUGH" --milestone "$IS_MILESTONE_TO_STAGING" --scraping-configured "$SCRAPING_ON" --database-container "$DBC" --spec-cli "$SPEC_CLI" --review-depth "$REVIEW_DEPTH" 2>/dev/null)
|
|
437
|
+
--thorough "$THOROUGH" --milestone "$IS_MILESTONE_TO_STAGING" --scraping-configured "$SCRAPING_ON" --database-container "$DBC" --spec-cli "$SPEC_CLI" --review-depth "$REVIEW_DEPTH" --design-routes "$DESIGN_ROUTES" 2>/dev/null)
|
|
432
438
|
SELECTED_AGENTS=$(printf '%s\n' "$ROSTER_OUT" | sed -n 's/^SELECTED_AGENTS=//p')
|
|
433
439
|
ROSTER_TIER=$(printf '%s\n' "$ROSTER_OUT" | sed -n 's/^TIER=//p')
|
|
434
440
|
ROSTER_REASON=$(printf '%s\n' "$ROSTER_OUT" | sed -n 's/^REASON=//p')
|
package/scripts/review-roster.sh
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# [--source-severity SEV] [--source-domain DOMAIN] [--contract-flags "HIGH_RISK CONTRACT_AUTH ..."]
|
|
12
12
|
# [--churn true|false] [--danger-zone true|false] [--thorough true|false] [--milestone true|false]
|
|
13
13
|
# [--scraping-configured true|false] [--database-container true|false] [--spec-cli true|false]
|
|
14
|
-
# [--review-depth STANDARD|EXTENDED]
|
|
14
|
+
# [--review-depth STANDARD|EXTENDED] [--design-routes true|false]
|
|
15
15
|
# Output (stdout): SELECTED_AGENTS=<canonical marker domains, space separated> TIER=<tier> REASON=<text>
|
|
16
16
|
# Exit: 0 always for a parseable call; 2 on an unknown flag (callers fall back to the full union, never a narrower roster).
|
|
17
17
|
#
|
|
@@ -36,7 +36,7 @@ set -u
|
|
|
36
36
|
|
|
37
37
|
S_AUTH=0; S_BILLING=0; S_CONCURRENCY=0; S_DATABASE=0; S_INFRA=0; S_SCRAPING=0; S_FRONTEND=0; S_API=0
|
|
38
38
|
LINES=""; NFILES=""; FILES_FILE=""; FIX_PR=false; SRC_SEV=""; SRC_DOM=""; CFLAGS=""
|
|
39
|
-
DEPTH=STANDARD; CHURN=false; DANGER=false; THOROUGH=false; MILESTONE=false; SCRAPING_ON=false; DB_CONTAINER=false; SPEC_CLI=false
|
|
39
|
+
DEPTH=STANDARD; DESIGN_ROUTES=false; CHURN=false; DANGER=false; THOROUGH=false; MILESTONE=false; SCRAPING_ON=false; DB_CONTAINER=false; SPEC_CLI=false
|
|
40
40
|
|
|
41
41
|
num() { case "${1:-}" in ''|*[!0-9]*) printf '0' ;; *) printf '%s' "$1" ;; esac; }
|
|
42
42
|
agent_domain() { local l; l=$(printf '%s' "${1}" | tr '[:upper:]' '[:lower:]'); case "$l" in infrastructure) l=infra ;; scraping) l=scraper ;; web) l=frontend ;; esac; printf '%s' "$l"; }
|
|
@@ -73,6 +73,7 @@ while [ $# -gt 0 ]; do
|
|
|
73
73
|
--scraping-configured) SCRAPING_ON="${2:-false}"; shift 2 ;;
|
|
74
74
|
--database-container) DB_CONTAINER="${2:-false}"; shift 2 ;;
|
|
75
75
|
--spec-cli) SPEC_CLI="${2:-false}"; shift 2 ;;
|
|
76
|
+
--design-routes) DESIGN_ROUTES="${2:-false}"; shift 2 ;;
|
|
76
77
|
--review-depth) [ "${2:-}" = "EXTENDED" ] && DEPTH=EXTENDED; shift 2 ;;
|
|
77
78
|
*) echo "review-roster: unknown argument: $1" >&2; exit 2 ;;
|
|
78
79
|
esac
|
|
@@ -202,6 +203,8 @@ hit '(^|/)app/(.*/)?route\.[cm]?[jt]sx?$|(^|/)pages/api/' && { add_agent Infra;
|
|
|
202
203
|
hit 'migration|\.sql$' && { add_agent Database; trig migration-path; }
|
|
203
204
|
hit '^sdk/|openapi.*\.json$|openapi-versions/' && { add_agent API; trig sdk-path; }
|
|
204
205
|
hit '(^|/)(web|app)/|\.(tsx|jsx)$|(^|/)next\.config\.[a-z]+$|(^|/)middleware\.(ts|js)$' && { add_agent Frontend; trig frontend-path; }
|
|
206
|
+
# forge#5330: the diff changes a user-visible route under forge.yaml design.routes (scripts/visual-gate.mjs --list is non-empty): the frontend persona judges the rendered result, in every tier
|
|
207
|
+
[ "$DESIGN_ROUTES" = "true" ] && { add_agent Frontend; trig design-route; }
|
|
205
208
|
hit '^bin/engine' && { add_agent Concurrency; trig bin-engine; }
|
|
206
209
|
if [ "$SPEC_CLI" = "true" ]; then
|
|
207
210
|
hit '^bin/' && { add_agent spec-cli; trig bin; }
|
|
@@ -278,5 +278,14 @@ run "docs/web-notes.md
|
|
|
278
278
|
svc/a.py" --scores "$SC_QUIET" --changed-lines 30 --changed-files 2
|
|
279
279
|
expect_not "no frontend path" frontend
|
|
280
280
|
|
|
281
|
+
# forge#5330: --design-routes true selects the frontend persona for a user-visible route outside the built-in frontend paths, in every tier
|
|
282
|
+
run "site/pages-src/hands.page" --scores "$SC_QUIET" --changed-lines 30 --changed-files 1
|
|
283
|
+
expect_not "design routes off" frontend
|
|
284
|
+
run "site/pages-src/hands.page" --scores "$SC_QUIET" --changed-lines 30 --changed-files 1 --design-routes true
|
|
285
|
+
expect_has "design routes on (small tier)" frontend
|
|
286
|
+
case "$REASON" in *design-route*) ok ;; *) bad "design-route trigger missing from '$REASON'" ;; esac
|
|
287
|
+
run "site/pages-src/hands.page" --scores "$SC_QUIET" --changed-lines 30 --changed-files 1 --design-routes false
|
|
288
|
+
expect_not "design routes false" frontend
|
|
289
|
+
|
|
281
290
|
echo "review-roster: $pass passed, $fail failed"
|
|
282
291
|
[ "$fail" -eq 0 ]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
/**
|
|
5
|
+
* scripts/visual-gate.mjs (#5369, #5330): the review-pr-staging visual gate. A thin CLI over bin/lean/design-gate.mjs, the same
|
|
6
|
+
* gate the lane precheck runs (no copy): it lists the new or changed user-visible routes of a staging bundle, then judges them
|
|
7
|
+
* against the rendered evidence (screenshots at every design.viewports width and the design-render-critique-loop verdict).
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node scripts/visual-gate.mjs --list [--config forge.yaml] (--files-file PATH|- | --base REF --head REF) [--root DIR]
|
|
11
|
+
* node scripts/visual-gate.mjs [same] [--spec yes|no | --specs-json PATH] [--evidence PATH] [--comment]
|
|
12
|
+
*
|
|
13
|
+
* --list print the routes to render ({routes, viewports, gate}) and exit 0; the reviewer renders them first
|
|
14
|
+
* --spec yes|no every route has (yes) or lacks (no) an approved FORGE:DESIGN_SPEC; default no
|
|
15
|
+
* --specs-json {"<route>": true|false} per route, resolved from each route's issue
|
|
16
|
+
* --evidence {"<route>": {"screenshots": ["shots/x-390.png", ...], "verdict": "PASS|ITERATE|BUDGET-EXHAUSTED"}}
|
|
17
|
+
* --comment print the FORGE:VISUAL_GATE comment markdown instead of JSON
|
|
18
|
+
* The deterministic source critique (empty boxes, placeholder copy, a text-only hero) always runs over the page files under --root.
|
|
19
|
+
* Exit: 0 PASS, ADVISORY or SKIP (design.routes unset: today's behaviour); 1 FAIL (design.gate: blocking and a finding) -> GATE_FAILURE; 2 usage.
|
|
20
|
+
*/
|
|
21
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
22
|
+
import { execFileSync } from "node:child_process";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
import { parseForgeYaml } from "../bin/forge-utils.mjs";
|
|
25
|
+
import { parseDesignConfig, designOn, designPages, visualGate, visualGateComment } from "../bin/lean/design-gate.mjs";
|
|
26
|
+
|
|
27
|
+
const argv = process.argv.slice(2);
|
|
28
|
+
const flag = (n) => { const i = argv.indexOf(n); return i < 0 ? null : (argv[i + 1] ?? ""); };
|
|
29
|
+
const has = (n) => argv.includes(n);
|
|
30
|
+
const usage = (m) => { process.stderr.write(`visual-gate: ${m}\n`); process.exit(2); };
|
|
31
|
+
const known = new Set(["--config", "--root", "--files-file", "--base", "--head", "--spec", "--specs-json", "--evidence", "--list", "--comment"]);
|
|
32
|
+
for (const a of argv) if (a.startsWith("--") && !known.has(a)) usage(`unknown argument: ${a}`);
|
|
33
|
+
|
|
34
|
+
const root = flag("--root") ?? process.cwd();
|
|
35
|
+
const confPath = flag("--config") ?? join(root, "forge.yaml");
|
|
36
|
+
const readJson = (p, what) => { try { return JSON.parse(readFileSync(p, "utf8")); } catch (e) { return usage(`cannot read ${what} ${p}: ${e.message}`); } };
|
|
37
|
+
|
|
38
|
+
let cfg = null;
|
|
39
|
+
try { cfg = parseDesignConfig(parseForgeYaml(readFileSync(confPath, "utf8"))?.design); } catch { cfg = null; }
|
|
40
|
+
if (!designOn(cfg)) { process.stdout.write(`${JSON.stringify({ gate: null, verdict: "SKIP", routes: [], rows: [], reason: "design.routes is unset" })}\n`); process.exit(0); }
|
|
41
|
+
|
|
42
|
+
let files;
|
|
43
|
+
if (flag("--files-file") != null) {
|
|
44
|
+
const p = flag("--files-file");
|
|
45
|
+
files = String(p === "-" ? readFileSync(0, "utf8") : readFileSync(p, "utf8")).split("\n").map((x) => x.trim()).filter(Boolean);
|
|
46
|
+
} else if (flag("--base") && flag("--head")) {
|
|
47
|
+
try { files = execFileSync("git", ["diff", "--name-only", `${flag("--base")}...${flag("--head")}`], { cwd: root, encoding: "utf8", timeout: 30000 }).split("\n").map((x) => x.trim()).filter(Boolean); }
|
|
48
|
+
catch (e) { usage(`git diff failed: ${String(e.message).split("\n")[0]}`); }
|
|
49
|
+
} else usage("give --files-file PATH|- or --base REF --head REF");
|
|
50
|
+
|
|
51
|
+
if (has("--list")) {
|
|
52
|
+
const g = visualGate({ cfg, files });
|
|
53
|
+
process.stdout.write(`${JSON.stringify({ gate: cfg.gate, viewports: cfg.viewports, directionsParam: cfg.directionsParam, routes: g.routes })}\n`);
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const sources = {};
|
|
58
|
+
for (const f of designPages(files, cfg)) { const p = join(root, f); if (existsSync(p)) { try { sources[f] = readFileSync(p, "utf8"); } catch { /* unreadable: no source critique for it */ } } }
|
|
59
|
+
const specFlag = flag("--spec");
|
|
60
|
+
const specs = flag("--specs-json") ? readJson(flag("--specs-json"), "specs") : /^(?:yes|true|1)$/i.test(specFlag ?? "");
|
|
61
|
+
const evidence = flag("--evidence") ? readJson(flag("--evidence"), "evidence") : {};
|
|
62
|
+
const g = visualGate({ cfg, files, specs, sources, evidence, rendered: true });
|
|
63
|
+
process.stdout.write(has("--comment") ? `${visualGateComment(g, evidence)}\n` : `${JSON.stringify(g)}\n`);
|
|
64
|
+
process.exit(g.verdict === "FAIL" ? 1 : 0);
|
|
@@ -59,6 +59,23 @@
|
|
|
59
59
|
|
|
60
60
|
**Rationale**: {why}
|
|
61
61
|
|
|
62
|
+
## Interfaces
|
|
63
|
+
|
|
64
|
+
One row per boundary between slices (required when the milestone plan has two or more items; a feature epic carries the
|
|
65
|
+
same section). Anchors are the paths that implement or call the boundary, in backticks; bootstrap-create registers each
|
|
66
|
+
row as an anchored decision so every lane touching those paths gets it as a preserve row, and changing one needs a
|
|
67
|
+
`supersedes` decision. Prefix an anchor `provider:` or `consumer:` to say which side it is. When the signature is
|
|
68
|
+
machine-readable (`POST /v1/x`, `refund(job_id, amount_micro)` or `queue q {field, field}`) and both sides are anchored,
|
|
69
|
+
`npx forgedock interfaces contract` generates a contract test (`node --test contracts/*.contract.test.mjs`) both sides run against the real source. Consumers
|
|
70
|
+
(`#issue` numbers or names) are reopened or get one filed issue when the interface is superseded. To record an
|
|
71
|
+
architecture choice the same way, add an `**Anchors**: \`path/\`` line to its section above.
|
|
72
|
+
|
|
73
|
+
| Boundary | Signature or schema | Auth mode | Owner issue | Anchors | Consumers |
|
|
74
|
+
|----------|---------------------|-----------|-------------|---------|-----------|
|
|
75
|
+
| {web -> api} | {POST /v1/x {body} -> {response}} | {API key only, no session cookie} | {issue key} | `{provider:src/api/}`, `{consumer:web/}` | {#issue or name} |
|
|
76
|
+
|
|
77
|
+
**Rationale**: {why these contracts; rejected alternative}
|
|
78
|
+
|
|
62
79
|
## Credentials
|
|
63
80
|
|
|
64
81
|
| Credential or account | Env var(s) | needs-human issue | Mock in dev/CI |
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #5338: the seam contract checker. Self-contained on purpose (node builtins only): `forgedock interfaces contract`
|
|
5
|
+
* copies this file next to the generated `<id>.contract.test.mjs` files, so a repo's provider and consumer CI both run
|
|
6
|
+
* `node --test contracts/*.contract.test.mjs` with no ForgeDock install and nothing mocked: the check reads the REAL source on both sides
|
|
7
|
+
* of the boundary and compares it with the contract the spike's `Interfaces` row declared.
|
|
8
|
+
*
|
|
9
|
+
* contract = { v:1, id, kind: "symbol"|"route"|"payload", boundary, auth, provider: [anchor], consumer: [anchor],
|
|
10
|
+
* symbol?: {name, params:[{name, optional, variadic}]}, route?: {method, path}, payload?: {fields:[name]} }
|
|
11
|
+
* Anchors are repo paths, `dir/` prefixes or globs. checkSeam is pure over { read(path), list() }.
|
|
12
|
+
* Returns { findings: [{side, file, line, detail}] } or { unchecked: reason } when a side has no files to read.
|
|
13
|
+
*/
|
|
14
|
+
import { execFileSync } from "node:child_process";
|
|
15
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
/** Escape every RegExp metacharacter (backslash included) in an identifier before building a pattern. */
|
|
18
|
+
const reEsc = (s) => String(s).replace(/[\\^$.*+?()[\]{}|/]/g, "\\$&");
|
|
19
|
+
|
|
20
|
+
const clean = (a) => String(a).replace(/^\.\//, "").replace(/^\/+/, "");
|
|
21
|
+
const globRe = (g) => new RegExp(`^${String(g).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\/?/g, "\u0000").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/\u0000/g, ".*")}$`);
|
|
22
|
+
/** Same rule as bin/lean/decisions.mjs anchorMatches (a parity test pins them together). */
|
|
23
|
+
export function anchorMatches(anchor, path) {
|
|
24
|
+
const a = clean(anchor), p = clean(path);
|
|
25
|
+
if (!a || !p) return false;
|
|
26
|
+
if (a.endsWith("/")) return p.startsWith(a);
|
|
27
|
+
return a === p || globRe(a).test(p) || p.startsWith(`${a}/`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const SOURCE = /\.(py|mjs|cjs|js|jsx|ts|tsx|mts|cts|go|rb|java|kt|rs|php|cs)$/i;
|
|
31
|
+
const lineOf = (text, idx) => text.slice(0, idx).split("\n").length;
|
|
32
|
+
const isId = (c) => /[A-Za-z0-9_$]/.test(c ?? "");
|
|
33
|
+
|
|
34
|
+
/** Index of the `)` closing the `(` at `open`, skipping strings; -1 when unbalanced. */
|
|
35
|
+
function closeParen(text, open) {
|
|
36
|
+
let depth = 0, q = null;
|
|
37
|
+
for (let i = open; i < text.length; i++) {
|
|
38
|
+
const c = text[i];
|
|
39
|
+
if (q) { if (c === "\\") i++; else if (c === q) q = null; continue; }
|
|
40
|
+
if (c === '"' || c === "'" || c === "`") q = c;
|
|
41
|
+
else if (c === "(" || c === "[" || c === "{") depth++;
|
|
42
|
+
else if (c === ")" || c === "]" || c === "}") { depth--; if (depth === 0) return i; }
|
|
43
|
+
}
|
|
44
|
+
return -1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Top-level comma split of an argument/parameter list. */
|
|
48
|
+
function splitTop(s) {
|
|
49
|
+
const out = []; let depth = 0, q = null, cur = "";
|
|
50
|
+
for (let i = 0; i < s.length; i++) {
|
|
51
|
+
const c = s[i];
|
|
52
|
+
if (q) { cur += c; if (c === "\\") cur += s[++i] ?? ""; else if (c === q) q = null; continue; }
|
|
53
|
+
if (c === '"' || c === "'" || c === "`") { q = c; cur += c; continue; }
|
|
54
|
+
if ("([{<".includes(c) && !(c === "<" && !/[A-Za-z]$/.test(cur.trim()))) depth++;
|
|
55
|
+
else if (")]}>".includes(c) && !(c === ">" && s[i - 1] === "=")) depth = Math.max(0, depth - 1);
|
|
56
|
+
if (c === "," && depth === 0) { out.push(cur); cur = ""; continue; }
|
|
57
|
+
cur += c;
|
|
58
|
+
}
|
|
59
|
+
if (cur.trim()) out.push(cur);
|
|
60
|
+
return out.map((x) => x.trim()).filter(Boolean);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The parameters a definition declares: [{name, optional, variadic}] (self/cls dropped; a destructured object is one param). */
|
|
64
|
+
function declaredParams(text) {
|
|
65
|
+
const out = [];
|
|
66
|
+
for (const raw of splitTop(text)) {
|
|
67
|
+
if (raw === "*" || raw === "/") continue;
|
|
68
|
+
const variadic = /^(\*\*?|\.\.\.)/.test(raw);
|
|
69
|
+
const body = raw.replace(/^(\*\*?|\.\.\.)/, "");
|
|
70
|
+
if (body.startsWith("{") || body.startsWith("[")) { out.push({ name: "{}", optional: /=/.test(raw), variadic }); continue; }
|
|
71
|
+
const m = /^([A-Za-z_$][\w$]*)(\?)?/.exec(body);
|
|
72
|
+
if (!m || m[1] === "self" || m[1] === "cls") continue;
|
|
73
|
+
out.push({ name: m[1], optional: Boolean(m[2]) || /(^|[^=!<>])=(?!=)/.test(body) || variadic, variadic });
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Definitions of `name` in a source text: [{line, params}]. */
|
|
79
|
+
function definitions(text, name) {
|
|
80
|
+
const out = [], re = new RegExp(`(?<![\\w$])${reEsc(name)}\\s*\\(`, "g");
|
|
81
|
+
for (let m; (m = re.exec(text));) {
|
|
82
|
+
const open = m.index + m[0].length - 1, close = closeParen(text, open);
|
|
83
|
+
if (close < 0) continue;
|
|
84
|
+
const before = text.slice(Math.max(0, m.index - 24), m.index), after = text.slice(close + 1, close + 80);
|
|
85
|
+
const def = /(\bdef|\bfunction\s*\*?|\bfunc|\bfn)\s+$/.test(before)
|
|
86
|
+
|| (/(^|\n)[ \t]*(?:(?:public|private|protected|static|async|export|get|set)\s+)*$/.test(before) && /^\s*(?::[^{;=]*)?\{/.test(after));
|
|
87
|
+
if (def) out.push({ line: lineOf(text, m.index), params: declaredParams(text.slice(open + 1, close)) });
|
|
88
|
+
}
|
|
89
|
+
const bound = new RegExp(`(?<![\\w$.])${reEsc(name)}\\s*[:=]\\s*(?:async\\s*)?(?:function\\s*\\*?\\s*[\\w$]*\\s*)?\\(`, "g");
|
|
90
|
+
for (let m; (m = bound.exec(text));) {
|
|
91
|
+
const open = m.index + m[0].length - 1, close = closeParen(text, open);
|
|
92
|
+
if (close < 0 || !/^\s*(?::[^=]*)?(=>|\{)/.test(text.slice(close + 1, close + 60))) continue;
|
|
93
|
+
out.push({ line: lineOf(text, m.index), params: declaredParams(text.slice(open + 1, close)) });
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Call sites of `name` in a source text: [{line, positional, keywords, dynamic}]; definitions and imports are skipped. */
|
|
99
|
+
function calls(text, name) {
|
|
100
|
+
const out = [], re = new RegExp(`(?<![\\w$])${reEsc(name)}\\s*\\(`, "g");
|
|
101
|
+
for (let m; (m = re.exec(text));) {
|
|
102
|
+
const before = text.slice(Math.max(0, m.index - 24), m.index);
|
|
103
|
+
if (/(\bdef|\bfunction\s*\*?|\bfunc|\bfn|\bnew|\bimport|\bfrom)\s+$/.test(before) || /(^|\n)[ \t]*(?:(?:public|private|protected|static|async|get|set)\s+)*$/.test(before) && /^\s*(?::[^{;=]*)?\{/.test(text.slice(closeParen(text, m.index + m[0].length - 1) + 1).slice(0, 80))) continue;
|
|
104
|
+
const open = m.index + m[0].length - 1, close = closeParen(text, open);
|
|
105
|
+
if (close < 0) continue;
|
|
106
|
+
const args = splitTop(text.slice(open + 1, close));
|
|
107
|
+
let positional = 0, dynamic = false;
|
|
108
|
+
const keywords = [];
|
|
109
|
+
for (const a of args) {
|
|
110
|
+
if (/^(\*\*?|\.\.\.)/.test(a)) { dynamic = true; continue; }
|
|
111
|
+
const kw = /^([A-Za-z_][\w]*)\s*=(?!=)/.exec(a);
|
|
112
|
+
if (kw) keywords.push(kw[1]); else positional++;
|
|
113
|
+
}
|
|
114
|
+
out.push({ line: lineOf(text, m.index), positional, keywords, dynamic });
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const names = (ps) => ps.map((p) => p.name).join(", ");
|
|
120
|
+
|
|
121
|
+
function checkSymbol(c, provider, consumer) {
|
|
122
|
+
const findings = [], want = c.symbol.params ?? [], wantNames = want.filter((p) => !p.variadic).map((p) => p.name);
|
|
123
|
+
let found = false;
|
|
124
|
+
for (const f of provider) {
|
|
125
|
+
for (const d of definitions(f.text, c.symbol.name)) {
|
|
126
|
+
found = true;
|
|
127
|
+
const have = d.params.filter((p) => !p.variadic);
|
|
128
|
+
const prefixOk = wantNames.every((n, i) => have[i]?.name === n);
|
|
129
|
+
const extraRequired = have.slice(wantNames.length).filter((p) => !p.optional);
|
|
130
|
+
if (!prefixOk || extraRequired.length) {
|
|
131
|
+
findings.push({ side: "provider", file: f.path, line: d.line, detail: `${c.symbol.name}(${names(d.params)}) does not match the declared ${c.symbol.name}(${names(want)}): a caller using the contract signature raises TypeError` });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!found) findings.push({ side: "provider", file: null, line: null, detail: `no definition of ${c.symbol.name}(...) under the provider anchors` });
|
|
136
|
+
for (const f of consumer) {
|
|
137
|
+
for (const k of calls(f.text, c.symbol.name)) {
|
|
138
|
+
if (k.dynamic) continue;
|
|
139
|
+
const slots = wantNames, byPos = slots.slice(0, k.positional), covered = new Set([...byPos, ...k.keywords]);
|
|
140
|
+
const missing = want.filter((p) => !p.optional && !p.variadic && !covered.has(p.name)).map((p) => p.name);
|
|
141
|
+
const unknown = k.keywords.filter((n) => !slots.includes(n) && !want.some((p) => p.variadic));
|
|
142
|
+
const tooMany = k.positional > slots.length && !want.some((p) => p.variadic);
|
|
143
|
+
if (missing.length || unknown.length || tooMany) {
|
|
144
|
+
findings.push({ side: "consumer", file: f.path, line: k.line, detail: `call ${c.symbol.name}(${k.positional} positional${k.keywords.length ? `, ${k.keywords.join("=, ")}=` : ""}) does not fit the declared ${c.symbol.name}(${names(want)})${missing.length ? `: missing ${missing.join(", ")}` : ""}${unknown.length ? `: unknown ${unknown.join(", ")}` : ""}${tooMany ? ": too many arguments" : ""}` });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return findings;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const WILD = "[^/\"'`\\s?#]+";
|
|
152
|
+
const pathPattern = (p) => p.split("/").map((seg) => (/^(\{[^}]+\}|:[\w-]+|\[[^\]]+\])$/.test(seg) ? WILD : seg.replace(/[.+^${}()|[\]\\*?]/g, "\\$&"))).join("/");
|
|
153
|
+
|
|
154
|
+
/** auth mode of an Interfaces row: api-key (an API key and no session/cookie/JWT), session, or other. */
|
|
155
|
+
export function authMode(auth) {
|
|
156
|
+
const t = String(auth ?? "").replace(/\b(?:no|not|never|without|except|instead of)\b[^,;.|]*/gi, " ");
|
|
157
|
+
const key = /api[\s_-]?key/i.test(t), session = /session|cookie|jwt|oauth/i.test(t);
|
|
158
|
+
return key && !session ? "api-key" : session ? "session" : "other";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const SESSION_LEAKS = [
|
|
162
|
+
[/credentials\s*:\s*["']include["']/, "sends credentials: include (the browser session cookie)"],
|
|
163
|
+
[/(headers\s*(?:\.get\s*\(|\[)\s*|["'`])cookie["'`]?\s*[:\])]/i, "forwards a Cookie header"],
|
|
164
|
+
[/\b(?:req|request|ctx)\.(?:headers\.cookie|cookies)\b|\bcookies\s*\(\s*\)/, "reads the request cookies"],
|
|
165
|
+
[/\bget(?:Server)?Session\s*\(|\bsession\.(?:access_?[tT]oken|token|jwt)\b|\bsession\[["'](?:access_?token|token|jwt)["']\]/, "reads the user session token"],
|
|
166
|
+
[/Bearer\s*\$\{[^}]*(?:session|jwt|access_?token|id_?token)[^}]*\}/i, "sends the session JWT as the Bearer credential"],
|
|
167
|
+
];
|
|
168
|
+
const KEY_SEND = /x-api-key|api[_-]?key|API_KEY/i;
|
|
169
|
+
|
|
170
|
+
function checkRoute(c, provider, consumer) {
|
|
171
|
+
const findings = [], { method, path } = c.route, pat = new RegExp(pathPattern(path)), verb = method.toLowerCase();
|
|
172
|
+
const segs = path.split("/").filter(Boolean);
|
|
173
|
+
const handled = provider.some((f) => {
|
|
174
|
+
for (const m of f.text.matchAll(new RegExp(`["'\`]${pathPattern(path)}/?["'\`]`, "g"))) {
|
|
175
|
+
const around = f.text.slice(Math.max(0, m.index - 80), m.index + m[0].length + 120);
|
|
176
|
+
if (new RegExp(`\\b${verb}\\b|["']${method}["']`, "i").test(around)) return true;
|
|
177
|
+
}
|
|
178
|
+
const dir = f.path.replace(/\/route\.[mc]?[jt]sx?$/, "");
|
|
179
|
+
return dir !== f.path && segs.every((s) => /^(\{[^}]+\}|:[\w-]+|\[[^\]]+\])$/.test(s) || dir.split("/").includes(s.replace(/^\[|\]$/g, ""))) && new RegExp(`export\\s+(?:async\\s+function|const)\\s+${method}\\b`).test(f.text);
|
|
180
|
+
});
|
|
181
|
+
if (!handled) findings.push({ side: "provider", file: null, line: null, detail: `no handler for ${method} ${path} under the provider anchors` });
|
|
182
|
+
if (authMode(c.auth) === "api-key") {
|
|
183
|
+
for (const f of consumer) {
|
|
184
|
+
if (!pat.test(f.text)) continue;
|
|
185
|
+
for (const [re, why] of SESSION_LEAKS) {
|
|
186
|
+
const m = re.exec(f.text);
|
|
187
|
+
if (m) findings.push({ side: "consumer", file: f.path, line: lineOf(f.text, m.index), detail: `${method} ${path} is ${c.auth || "API-key only"} but this caller ${why}` });
|
|
188
|
+
}
|
|
189
|
+
if (!KEY_SEND.test(f.text)) findings.push({ side: "consumer", file: f.path, line: lineOf(f.text, f.text.search(pat)), detail: `${method} ${path} needs an API key but this caller never sends one` });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return findings;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function checkPayload(c, provider, consumer) {
|
|
196
|
+
const findings = [];
|
|
197
|
+
for (const [side, files] of [["provider", provider], ["consumer", consumer]]) {
|
|
198
|
+
const text = files.map((f) => f.text).join("\n");
|
|
199
|
+
for (const field of c.payload.fields) {
|
|
200
|
+
if (!new RegExp(`(?<![\\w$])${reEsc(field)}(?![\\w$])`).test(text)) findings.push({ side, file: null, line: null, detail: `payload field "${field}" never appears under the ${side} anchors: it is accepted on one side and dropped on the other` });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return findings;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Pure check of one contract against the repo files. */
|
|
207
|
+
export function checkSeam(contract, { read, list }) {
|
|
208
|
+
const all = list().map(clean).filter((p) => SOURCE.test(p));
|
|
209
|
+
const side = (anchors) => all.filter((p) => (anchors ?? []).some((a) => anchorMatches(a, p))).map((p) => ({ path: p, text: String(read(p) ?? "") }));
|
|
210
|
+
const provider = side(contract.provider), consumer = side(contract.consumer);
|
|
211
|
+
if (!provider.length || !consumer.length) return { findings: [], unchecked: `${contract.id}: no source files under the ${provider.length ? "consumer" : "provider"} anchors (declare both sides as \`provider:<path>\` and \`consumer:<path>\` in the Anchors cell)` };
|
|
212
|
+
const run = { symbol: checkSymbol, route: checkRoute, payload: checkPayload }[contract.kind];
|
|
213
|
+
if (!run || !contract[contract.kind]) return { findings: [], unchecked: `${contract.id}: unknown contract kind ${contract.kind}` };
|
|
214
|
+
return { findings: run(contract, provider, consumer) };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Repo files: git's tracked and untracked-not-ignored list, else a directory walk. */
|
|
218
|
+
export function repoFiles(root) {
|
|
219
|
+
try { return execFileSync("git", ["ls-files", "-co", "--exclude-standard"], { cwd: root, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 }).split("\n").filter(Boolean); } catch { /* not a git checkout */ }
|
|
220
|
+
const out = [], walk = (dir, rel) => {
|
|
221
|
+
for (const e of readdirSync(join(root, dir), { withFileTypes: true })) {
|
|
222
|
+
if (e.name === ".git" || e.name === "node_modules") continue;
|
|
223
|
+
const p = rel ? `${rel}/${e.name}` : e.name;
|
|
224
|
+
if (e.isDirectory()) walk(join(dir, e.name), p); else out.push(p);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
walk(".", "");
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** checkSeam over the real files under `root` (what the generated tests call). */
|
|
232
|
+
export function checkSeamAt(contract, root) {
|
|
233
|
+
return checkSeam(contract, { list: () => repoFiles(root), read: (p) => { try { return readFileSync(join(root, p), "utf8"); } catch { return ""; } } });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export const formatFindings = (findings) => findings.map((f) => `${f.side}${f.file ? ` ${f.file}${f.line ? `:${f.line}` : ""}` : ""}: ${f.detail}`).join("\n");
|