rungate 0.8.26 → 0.8.28

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.
@@ -12,6 +12,7 @@
12
12
  * bun scripts/sync-sc-status.ts # Run targeted tests and flip checkboxes
13
13
  * bun scripts/sync-sc-status.ts --dry-run # Show what would flip without changing files
14
14
  * bun scripts/sync-sc-status.ts --report # Output per-spec coverage report
15
+ * rungate sync-sc-status [--dry-run] [--only …] # a consumer, on its own tree (#2360)
15
16
  */
16
17
 
17
18
  import { parseArgs } from "util";
@@ -43,7 +44,49 @@ import {
43
44
 
44
45
  export { isTemplateSpec };
45
46
 
46
- const ROOT = join(import.meta.dir, "..");
47
+ /**
48
+ * The tree whose specs and tests this run reads (#2360).
49
+ *
50
+ * `--project-root <dir>` (or `=<dir>`) names it, and the CLI dispatcher
51
+ * appends the caller's directory for every consumer. Absent, it is this
52
+ * script's own repository, so `bun scripts/sync-sc-status.ts` and the
53
+ * `posttest` hook behave exactly as before. Given with no directory it
54
+ * REFUSES: falling back to the package would read rungate's specs and
55
+ * report on them as the consumer's.
56
+ */
57
+ export function resolveSyncRoot(argv: readonly string[]): { root: string } | { refusal: string } {
58
+ const { tokens } = parseArgs({
59
+ args: [...argv],
60
+ options: { "project-root": { type: "string" } },
61
+ strict: false,
62
+ allowPositionals: true,
63
+ tokens: true,
64
+ });
65
+ let given = false;
66
+ let value: string | undefined;
67
+ for (const t of tokens ?? []) {
68
+ if (t.kind !== "option" || t.name !== "project-root") continue;
69
+ given = true;
70
+ value = t.value; // the last one wins, as for every other flag
71
+ }
72
+ if (!given) return { root: join(import.meta.dir, "..") };
73
+ if (value === undefined || value === "" || value.startsWith("-")) {
74
+ return {
75
+ refusal:
76
+ "--project-root was given with no directory after it. Refusing rather than falling back to this " +
77
+ "package's own specs, which would be reported as yours.",
78
+ };
79
+ }
80
+ return { root: value };
81
+ }
82
+
83
+ // Only as the ENTRY POINT (review of #2365). finding-promotion, create-sc and
84
+ // board-scope import the readers below and may carry a --project-root of their
85
+ // own; an importer keeps this package's tree, exactly as before #2360.
86
+ const ROOT_READING: ReturnType<typeof resolveSyncRoot> = import.meta.main
87
+ ? resolveSyncRoot(process.argv.slice(2))
88
+ : { root: join(import.meta.dir, "..") };
89
+ const ROOT = "root" in ROOT_READING ? ROOT_READING.root : join(import.meta.dir, "..");
47
90
  const SPECS_DIR = join(ROOT, "specs");
48
91
  const TEST_DIR = join(ROOT, "test");
49
92
  const dryRun = process.argv.includes("--dry-run");
@@ -91,12 +134,17 @@ export function unknownSyncArgs(argv: readonly string[]): string[] {
91
134
  if (valued.length > 0) return valued;
92
135
  const { tokens } = parseArgs({
93
136
  args: [...argv],
94
- options: { only: { type: "string" }, "dry-run": { type: "boolean" }, report: { type: "boolean" } },
137
+ options: {
138
+ only: { type: "string" },
139
+ "project-root": { type: "string" },
140
+ "dry-run": { type: "boolean" },
141
+ report: { type: "boolean" },
142
+ },
95
143
  strict: false,
96
144
  allowPositionals: true,
97
145
  tokens: true,
98
146
  });
99
- const known = new Set(["only", "dry-run", "report"]);
147
+ const known = new Set(["only", "project-root", "dry-run", "report"]);
100
148
  const out: string[] = [];
101
149
  for (const t of tokens ?? []) {
102
150
  if (t.kind === "option" && t.name === "only" && (t.value === undefined || t.value.startsWith("-"))) {
@@ -859,7 +907,19 @@ if (isDirectExecution) {
859
907
  if (unknownArgs.length > 0) {
860
908
  console.error(
861
909
  `sync-sc-status: cannot use argument(s): ${unknownArgs.join(", ")}. Nothing was read or written. ` +
862
- "It takes --dry-run, --report and --only <SC-id,…>; there is no --help.",
910
+ "It takes --dry-run, --report, --only <SC-id,…> and --project-root <dir>; there is no --help.",
911
+ );
912
+ process.exit(1);
913
+ }
914
+ if ("refusal" in ROOT_READING) {
915
+ console.error(`sync-sc-status: ${ROOT_READING.refusal} Nothing was read or written.`);
916
+ process.exit(1);
917
+ }
918
+ // #2360: a root with no specs/ is a reading not taken, not "all checked".
919
+ if (!existsSync(SPECS_DIR)) {
920
+ console.error(
921
+ `sync-sc-status: no specs directory at ${SPECS_DIR}. UNMEASURED — nothing was read, which is not the same ` +
922
+ `as every criterion being ticked. Pass --project-root <dir> naming the tree whose specs/ you mean.`,
863
923
  );
864
924
  process.exit(1);
865
925
  }