Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
"test:play-verify-loop": "tsx --test scripts/play-verify-loop.test.ts",
"test:pro-commit-conformance": "tsx --test scripts/pro-commit-conformance.test.ts",
"test:doc-links": "tsx --test scripts/doc-links.test.ts",
"test:doc-counts": "tsx --test scripts/doc-counts.test.ts",
"test:safety-refs": "tsx --test scripts/safety-test-refs.test.ts",
"test:pro-pnl": "tsx --test scripts/verify-pro-pnl.test.ts",
"play": "npm -w @sui-options/pro-options run play",
"build:sdk": "npm -w @wick/sdk run build",
Expand All @@ -112,7 +114,7 @@
"bots:run": "npm -w wick-bots run run",
"bots:tick": "npm -w wick-bots run tick",
"test": "npm run test:offline && npm run test:live",
"test:offline": "npm -w @wick/sdk test && npm -w wick-bots test && npm -w wick-keeper test && npm -w @wick/api test && npm run test:candle-vision && npm -w @sui-options/candle-vision-react test && npm run test:pro-options && npm run test:pro-fairness && npm run test:verify-pro-round && npm run test:play-verify-loop && npm run test:pro-commit-conformance && npm run test:pro-pnl && npm run test:verify-v4 && npm run test:audit-rugs && npm run test:rug-roll && npm run test:verify-payout && npm run test:verify-barriers && npm run test:vault-solvency && npm run test:verify-randomness && npm run test:audit-deployment && npm run test:gas-report && npm run test:verify-replay && npm run test:greeks-display && npm run test:audit-ride && npm run test:chart-live && npm run test:faucet-runway && npm run test:live-verify && npm run test:safety && npm run test:doc-links && npm run test:cold-gate-coverage",
"test:offline": "npm -w @wick/sdk test && npm -w wick-bots test && npm -w wick-keeper test && npm -w @wick/api test && npm run test:candle-vision && npm -w @sui-options/candle-vision-react test && npm run test:pro-options && npm run test:pro-fairness && npm run test:verify-pro-round && npm run test:play-verify-loop && npm run test:pro-commit-conformance && npm run test:pro-pnl && npm run test:verify-v4 && npm run test:audit-rugs && npm run test:rug-roll && npm run test:verify-payout && npm run test:verify-barriers && npm run test:vault-solvency && npm run test:verify-randomness && npm run test:audit-deployment && npm run test:gas-report && npm run test:verify-replay && npm run test:greeks-display && npm run test:audit-ride && npm run test:chart-live && npm run test:faucet-runway && npm run test:live-verify && npm run test:safety && npm run test:doc-links && npm run test:doc-counts && npm run test:safety-refs && npm run test:cold-gate-coverage",
"test:live": "echo 'no network-requiring unit tests — live verification runs via e2e:* and check:* targets'",
"test:move": "cd move && sui move test",
"conformance": "npm -w @wick/sdk run conformance",
Expand Down
50 changes: 50 additions & 0 deletions scripts/doc-counts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Cold-gate enforcement for the Move-test-count docs.
*
* scripts/check-doc-counts.sh is a fast, no-compile guard: it asserts every
* judge-facing doc states the SAME Move-test count AND that the count matches the
* actual `#[test]` total in move/ (an exact `sui move test` proxy — see #738). It
* monitors all the count forms a doc can use: "N/N tests", bolded "**N/N** Move
* tests" (#750), the badge URL + ALT text (#751), "N Move tests", "Total tests: N",
* "N/N passing" (#749), and the "# N/N" command comment. 9/9 forms covered.
*
* Without this test the guard only ran when someone remembered to. Wiring it into
* the cold gate means a Move test added WITHOUT `npm run sync:count` fails `npm
* test`, with a one-command fix — instead of a judge running `sui move test` and
* seeing a number that mismatches the README. Mirrors test:doc-links (the doc-link
* consistency check already in the gate).
*
* Run: npx tsx --test scripts/doc-counts.test.ts
*/
import { test } from "node:test";
import { strict as assert } from "node:assert";
import { execFileSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";

const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");

test("docs state ONE Move-test count that matches the source (check:doc-counts)", () => {
let out = "";
try {
// The guard cd's to the repo root itself; run from there for good measure.
out = execFileSync("bash", ["scripts/check-doc-counts.sh"], {
cwd: repoRoot,
encoding: "utf8",
});
} catch (err) {
const e = err as { stdout?: string; stderr?: string; message?: string };
assert.fail(
`check:doc-counts FAILED — a doc states a Move-test count that disagrees with the\n` +
`others or with the move/ source. The one-command fix is: npm run sync:count\n\n` +
`${e.stdout ?? e.stderr ?? e.message ?? "(no output)"}`,
);
}
// Belt-and-suspenders: a 0 exit must be the genuine all-consistent message, not
// some other early return.
assert.match(
out,
/consistent across all docs AND matches move\/ source/,
`check:doc-counts exited 0 but without the all-consistent confirmation:\n${out}`,
);
});
69 changes: 69 additions & 0 deletions scripts/safety-test-refs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Guard: every test named in move/SAFETY.md exists as a Move fun.
*
* SAFETY.md is the judge-facing "safety property → test" traceability map; its
* intro says: "Run one property: `sui move test <test_name>` (substring match on
* the function)." If a test is renamed or removed but its SAFETY.md reference
* isn't updated, a judge running that command finds 0 tests — a broken honesty
* claim ("every fund-safety property maps to a named test you can run").
*
* The fleet edits SAFETY.md frequently (mapping new properties — #739/#743/#745),
* so a stale/typo'd reference is plausible. This catches it in the cold gate.
* Mirrors test:doc-links (link refs) + test:doc-counts (count refs).
*
* Run: npx tsx --test scripts/safety-test-refs.test.ts
*/
import { test } from "node:test";
import { strict as assert } from "node:assert";
import { readFileSync, readdirSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, resolve, join } from "node:path";

const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");

/** Every `fun NAME` declared in the Move package (tests + sources). */
function moveFunNames(): Set<string> {
const names = new Set<string>();
for (const d of ["move/sources", "move/tests"]) {
const dir = join(repoRoot, d);
for (const f of readdirSync(dir)) {
if (!f.endsWith(".move")) continue;
const src = readFileSync(join(dir, f), "utf8");
for (const m of src.matchAll(/\bfun\s+([a-z_][a-z0-9_]*)/g)) names.add(m[1]);
}
}
return names;
}

/** Backtick-quoted test names in SAFETY.md's middle table column: | prop | TESTS | file |. */
function safetyTestRefs(): string[] {
const md = readFileSync(join(repoRoot, "move", "SAFETY.md"), "utf8");
const refs = new Set<string>();
for (const line of md.split("\n")) {
if (!line.startsWith("|") || line.includes("---")) continue; // data rows only
const testsCol = line.split("|")[2] ?? ""; // index 2 = the middle (tests) column
Comment on lines +42 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Only parse SAFETY tables that list tests

This treats the second column of every Markdown table as test references, but move/SAFETY.md also has tables such as Property | Proof | Where; the current parser already extracts proof prose identifiers like rug_chance_bps and multiplier_bps and validates them as if they were runnable tests. When a proof row legitimately mentions a field, script, or other non-fun identifier, the cold gate will fail even though no SAFETY test reference is stale, so the parser should track the table header and only scan Property | Test | File rows.

Useful? React with 👍 / 👎.

for (const m of testsCol.matchAll(/`([a-z_][a-z0-9_]{6,})`/g)) {
const n = m[1];
if (n.includes("_tests") || n.endsWith("_move")) continue; // file refs, not test names
refs.add(n);
}
}
return [...refs];
}

test("every test named in move/SAFETY.md exists as a Move fun (judges run `sui move test <name>`)", () => {
const funs = moveFunNames();
const refs = safetyTestRefs();
// Sanity: the parser must actually find the table, not silently match nothing.
assert.ok(
refs.length > 100,
`expected 100+ test refs parsed from SAFETY.md, got ${refs.length} — did the table format change?`,
);
const missing = refs.filter((r) => !funs.has(r));
assert.deepEqual(
missing,
[],
`move/SAFETY.md references test name(s) that no longer exist as a Move fun — a judge running ` +
`'sui move test <name>' would find 0 tests. Update SAFETY.md (or restore the test). Stale: ${missing.join(", ")}`,
);
});
Loading