@cosmicdrift/kumiko-guards 0.299.0 → 0.305.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/README.md CHANGED
@@ -24,7 +24,12 @@ without their own `node_modules` resolve via the parent install) and fails
24
24
  closed with a `bun install` / `PRE_PUSH_SKIP=1` hint when none exists. Inside
25
25
  the cosmicdriftgamestudio parent workspace it runs a scoped `bun check` for
26
26
  the pushing repo only; in a standalone clone it runs the repo's own
27
- `package.json` `test` script. Set `PRE_PUSH_SKIP=1` to bypass.
27
+ `package.json` `test` script. From a `.wt/<name>` worktree under the parent
28
+ workspace it runs a tracked `scripts/check-wt.sh` if present, otherwise the
29
+ worktree's own `package.json` scripts `typecheck`, `lint`, `test`, and
30
+ `test:dom` (whichever are declared), directly in the worktree — the parent's
31
+ `bun check` would otherwise check the main checkout instead. Set
32
+ `PRE_PUSH_SKIP=1` to bypass.
28
33
 
29
34
  Extension point: a tracked, executable `scripts/pre-push-extra.sh` runs
30
35
  before the main check in every branch (worktree, parent-scoped, and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-guards",
3
- "version": "0.299.0",
3
+ "version": "0.305.0",
4
4
  "description": "AST-based security guards for Kumiko repos: direct-fs/fetch, tenant escalation, admin-API, escape hatches and related checks, run over a shared ts-morph project.",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -28,7 +28,7 @@
28
28
  "kumiko-pre-push": "./src/pre-push.sh"
29
29
  },
30
30
  "dependencies": {
31
- "@cosmicdrift/kumiko-repo-manifest": "0.299.0",
31
+ "@cosmicdrift/kumiko-repo-manifest": "0.305.0",
32
32
  "ts-morph": "^28.0.0"
33
33
  },
34
34
  "publishConfig": {
package/src/changes.json CHANGED
@@ -1,4 +1,16 @@
1
1
  [
2
+ {
3
+ "version": "0.301.0",
4
+ "type": "fix",
5
+ "title": "kumiko-pre-push refuses a standalone push without a package.json test script with a clear message",
6
+ "detail": "Previously the standalone branch ran bun run test unconditionally, so a repo without a test script only saw bun's Script not found error. The hook still fails closed (exit 1) but now names the missing script and the PRE_PUSH_SKIP escape."
7
+ },
8
+ {
9
+ "version": "0.301.0",
10
+ "type": "improvement",
11
+ "title": "kumiko-pre-push runs a worktree's own package.json scripts instead of the parent check on the main checkout",
12
+ "detail": "A push from a .wt/<name> worktree under the parent workspace without a tracked scripts/check-wt.sh used to fall into the parent-scoped kumiko check, which checks the main checkout of that repo, not the pushed worktree. It now runs the worktree's own typecheck, lint, test and test:dom scripts (whichever are declared) in the worktree, collects failures and refuses the push if any fail or if no test script exists. A tracked scripts/check-wt.sh still takes precedence; regular checkouts keep the parent-scoped check."
13
+ },
2
14
  {
3
15
  "version": "0.299.0",
4
16
  "type": "improvement",
package/src/pre-push.sh CHANGED
@@ -2,12 +2,20 @@
2
2
  # Pre-push hook — runs scoped `bun check` before allowing push.
3
3
  #
4
4
  # Logic:
5
- # 1. If running inside the cosmicdriftgamestudio Parent-Workspace,
5
+ # 1. If running inside a worktree with a tracked, executable
6
+ # scripts/check-wt.sh, delegate to it.
7
+ # 2. Else if running inside a worktree under the parent workspace (no
8
+ # check-wt.sh), run this worktree's own package.json scripts
9
+ # (typecheck, lint, test, test:dom) directly — the parent's
10
+ # `bun check` would otherwise check the main checkout instead of the
11
+ # worktree.
12
+ # 3. Else if running inside the cosmicdriftgamestudio Parent-Workspace,
6
13
  # delegate to its `bun check` with KUMIKO_CLI_SCOPE set to THIS
7
14
  # sub-repo only — so a push from one sub-repo doesn't run
8
15
  # Biome/TS/Tests for its siblings as well.
9
- # 2. Else (standalone clone outside the parent workspace): run the
10
- # sub-repo's own package.json `test` script.
16
+ # 4. Else (standalone clone outside the parent workspace): run the
17
+ # sub-repo's own package.json `test` script — refuses the push if that
18
+ # script is missing.
11
19
  #
12
20
  # Extension point: a tracked, executable scripts/pre-push-extra.sh runs
13
21
  # before the main check in every branch above, with KUMIKO_PUSH_REPO_ROOT
@@ -60,6 +68,18 @@ while [ "$DIR" != "/" ]; do
60
68
  DIR="$(dirname "$DIR")"
61
69
  done
62
70
 
71
+ # Exit 0 iff $REPO_ROOT/package.json has a string scripts[NAME]. Runs from /
72
+ # so the repo's bunfig (e.g. a throwing top-level preload) can't turn the
73
+ # probe into a false "no script"; path and name go in as argv, never
74
+ # interpolated into the JS source.
75
+ has_package_script() {
76
+ (cd / && bun -e '
77
+ const pkg = await Bun.file(process.argv[1]).json().catch(() => null);
78
+ const name = process.argv[2];
79
+ process.exit(pkg && typeof pkg.scripts?.[name] === "string" ? 0 : 1);
80
+ ' "$REPO_ROOT/package.json" "$1") >/dev/null 2>&1
81
+ }
82
+
63
83
  if git -C "$REPO_ROOT" ls-files --error-unmatch scripts/pre-push-extra.sh >/dev/null 2>&1 \
64
84
  && [ -x "$REPO_ROOT/scripts/pre-push-extra.sh" ]; then
65
85
  echo "[pre-push] running scripts/pre-push-extra.sh…"
@@ -78,15 +98,55 @@ if [ "$(git rev-parse --git-dir)" != "$(git rev-parse --git-common-dir)" ] \
78
98
  cd "$REPO_ROOT" && exec "$REPO_ROOT/scripts/check-wt.sh"
79
99
  fi
80
100
 
101
+ # infra#899: no tracked scripts/check-wt.sh — the parent-scoped `bun check`
102
+ # branch below would check the main checkout, not this worktree. Run the
103
+ # worktree's own package.json scripts directly instead (only when nested
104
+ # under the parent workspace; a standalone worktree's own `bun run test`
105
+ # already checks the right code).
106
+ if [ "$(git rev-parse --git-dir)" != "$(git rev-parse --git-common-dir)" ] \
107
+ && [ -n "$PARENT_DIR" ]; then
108
+ cd "$REPO_ROOT"
109
+ echo "[pre-push] worktree without scripts/check-wt.sh — running this worktree's package.json scripts (typecheck, lint, test, test:dom)…"
110
+ if ! has_package_script test; then
111
+ echo "[pre-push] FATAL: worktree without a package.json \"test\" script — nothing to run, refusing push." >&2
112
+ echo "Add a \"test\" script to package.json, or set PRE_PUSH_SKIP=1 to bypass (use sparingly)." >&2
113
+ exit 1
114
+ fi
115
+ FAILED=""
116
+ for SCRIPT_NAME in typecheck lint test test:dom; do
117
+ if has_package_script "$SCRIPT_NAME"; then
118
+ echo "[pre-push] bun run $SCRIPT_NAME"
119
+ if ! bun run "$SCRIPT_NAME"; then
120
+ FAILED="$FAILED $SCRIPT_NAME"
121
+ fi
122
+ else
123
+ echo "[pre-push] $SCRIPT_NAME: no script, skipped"
124
+ fi
125
+ done
126
+ if [ -n "$FAILED" ]; then
127
+ echo "[pre-push] worktree check failed:$FAILED" >&2
128
+ exit 1
129
+ fi
130
+ exit 0
131
+ fi
132
+
81
133
  if [ -n "$PARENT_DIR" ]; then
82
134
  echo "[pre-push] bun check (scoped: $REPO_NAME)…"
83
135
  # KUMIKO_PUSH_REPO_ROOT forwards this checkout to guards that need it
84
- # (worktrees with scripts/check-wt.sh take the branch above and skip this path).
136
+ # (worktrees never reach this branch — check-wt.sh or the generic
137
+ # worktree branch above always exits first).
85
138
  cd "$PARENT_DIR" && KUMIKO_CLI_SCOPE="$REPO_NAME" KUMIKO_PUSH_REPO_ROOT="$REPO_ROOT" bun kumiko-framework/bin/kumiko.ts check
86
139
  else
87
140
  echo "[pre-push] bun run test (standalone)…"
88
141
  # `bun test` globs everything the default bunfig doesn't exclude, including
89
142
  # integration tests; the package.json `test` script carries the repo's own
90
143
  # exclusions (e.g. integration suites needing infra this hook doesn't have).
144
+ # A missing `test` script would otherwise surface as bun's unhelpful
145
+ # "Script not found" — check it up front with a clear, actionable message.
146
+ if ! has_package_script test; then
147
+ echo "[pre-push] FATAL: standalone clone without a package.json \"test\" script — nothing to run, refusing push." >&2
148
+ echo "Add a \"test\" script to package.json, or set PRE_PUSH_SKIP=1 to bypass (use sparingly)." >&2
149
+ exit 1
150
+ fi
91
151
  cd "$REPO_ROOT" && bun run test
92
152
  fi