@cosmicdrift/kumiko-guards 0.413.1 → 0.414.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 +15 -9
- package/package.json +4 -4
- package/src/_lib/agent-docs-api-nodes.ts +9 -2
- package/src/_lib/agent-docs-api-render.ts +31 -10
- package/src/_lib/agent-docs-api.ts +13 -9
- package/src/_lib/agent-docs-feature-imports.ts +12 -1
- package/src/_lib/baseline-compare.ts +1 -2
- package/src/_lib/doc-status.ts +8 -4
- package/src/_lib/dockerfile.ts +28 -5
- package/src/_lib/escaped-literal.ts +26 -0
- package/src/_lib/npm-registry.ts +2 -2
- package/src/_lib/run-slots.ts +4 -6
- package/src/_lib/security-audit.ts +22 -6
- package/src/_lib/test-es-raw-writes.ts +5 -3
- package/src/changes.json +44 -0
- package/src/check-security.ts +4 -3
- package/src/guard-app-dockerfile.ts +29 -12
- package/src/guard-ignore-tag-reason.ts +18 -4
- package/src/guard-internal-subpath-imports.ts +35 -25
- package/src/guard-rls-session-settings.ts +48 -6
- package/src/guard-schema-cli-features.ts +22 -1
- package/src/guard-test-es-row-writes.ts +2 -1
- package/src/guard-unsafe-array-param.ts +4 -7
- package/src/pre-push.sh +46 -6
- package/src/run-guards.ts +0 -28
- package/src/run-repo-checks.ts +0 -6
- package/src/run-steps-parallel.ts +4 -4
- package/src/run-ui-guards.ts +1 -15
- package/src/_lib/german-test-title.ts +0 -94
- package/src/_lib/primitives-access.ts +0 -23
- package/src/check-predicates.ts +0 -244
- package/src/guard-admin-api.ts +0 -138
- package/src/guard-direct-fetch.ts +0 -161
- package/src/guard-error-reasons.ts +0 -210
- package/src/guard-event-store-writes.ts +0 -124
- package/src/guard-i18n-locale-terminology.ts +0 -134
- package/src/guard-no-custom-primitives.ts +0 -193
- package/src/guard-no-date-api.ts +0 -183
- package/src/guard-no-direct-fs.ts +0 -346
- package/src/guard-no-direct-process-env.ts +0 -127
- package/src/guard-no-inline-styles.ts +0 -64
- package/src/guard-no-raw-hooks.ts +0 -80
- package/src/guard-no-temporal-polyfill-import.ts +0 -131
- package/src/guard-primitives-discipline.ts +0 -357
- package/src/guard-raw-classname.ts +0 -117
- package/src/guard-raw-interactive-elements.ts +0 -164
- package/src/guard-restricted-symbols.ts +0 -155
- package/src/guard-silent-skip.ts +0 -186
- package/src/guard-test-es-fixtures.ts +0 -85
- package/src/guard-test-title.ts +0 -159
- package/src/guard-thin-wrappers.ts +0 -471
- package/src/guard-unsafe-json-parse.ts +0 -87
|
@@ -56,17 +56,21 @@ export type AppDockerfileFindings = {
|
|
|
56
56
|
readonly warnings: readonly string[];
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
function
|
|
60
|
-
if (bunfigText === undefined) return
|
|
59
|
+
function bunfigScopeEntry(bunfigText: string | undefined): unknown {
|
|
60
|
+
if (bunfigText === undefined) return undefined;
|
|
61
61
|
let parsed: unknown;
|
|
62
62
|
try {
|
|
63
63
|
parsed = Bun.TOML.parse(bunfigText);
|
|
64
64
|
} catch {
|
|
65
|
-
return
|
|
65
|
+
return undefined;
|
|
66
66
|
}
|
|
67
67
|
const install = isPlainObject(parsed) ? parsed["install"] : undefined;
|
|
68
68
|
const scopes = isPlainObject(install) ? install["scopes"] : undefined;
|
|
69
|
-
return isPlainObject(scopes)
|
|
69
|
+
return isPlainObject(scopes) ? scopes[PRIVATE_SCOPE] : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function hasBunfigScope(bunfigText: string | undefined): boolean {
|
|
73
|
+
return bunfigScopeEntry(bunfigText) !== undefined;
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
// A registry line without an auth token routes the scope to GitHub Packages
|
|
@@ -79,14 +83,27 @@ function hasNpmrcScope(npmrcText: string | undefined): boolean {
|
|
|
79
83
|
);
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
function variablesIn(text: string | undefined): string[] {
|
|
87
|
+
return [...(text ?? "").matchAll(SHELL_VARIABLE_RE)].flatMap((match) =>
|
|
88
|
+
match[1] ? [match[1]] : [],
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Only the private scope's own credential counts: a variable for another
|
|
93
|
+
// registry would let a mount of the wrong variable pass the guard.
|
|
94
|
+
function tokenVariablesOf(
|
|
95
|
+
bunfigText: string | undefined,
|
|
96
|
+
npmrcText: string | undefined,
|
|
97
|
+
): Set<string> {
|
|
98
|
+
const scope = bunfigScopeEntry(bunfigText);
|
|
99
|
+
const bunfigToken = isPlainObject(scope) ? scope["token"] : undefined;
|
|
100
|
+
const npmrcAuthLine = /^\s*\/\/npm\.pkg\.github\.com\/:_authToken=(.*)$/m.exec(
|
|
101
|
+
npmrcText ?? "",
|
|
102
|
+
)?.[1];
|
|
103
|
+
return new Set([
|
|
104
|
+
...variablesIn(typeof bunfigToken === "string" ? bunfigToken : undefined),
|
|
105
|
+
...variablesIn(npmrcAuthLine),
|
|
106
|
+
]);
|
|
90
107
|
}
|
|
91
108
|
|
|
92
109
|
function registryAuthViolation(input: AppDockerfileInput, stage: DockerStage): string | undefined {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
|
-
* Ignore-Tag-Reason Guard: every `kumiko-lint-ignore <slug> <reason>` comment states a real reason.
|
|
3
|
+
* Ignore-Tag-Reason Guard: every `kumiko-lint-ignore <slug> <reason>` and `biome-ignore[-all|-start] <rule>: <reason>` comment states a real reason.
|
|
4
4
|
* A missing reason, a generic one (`todo`, `legacy`, ...) or one shorter than three words ("invite-flow")
|
|
5
5
|
* only silences a guard without telling the next reader why the exception is safe. Existing hits are
|
|
6
6
|
* frozen per file in `.kumiko-ignore-tag-reason-baseline.json` and may not grow; without a baseline
|
|
@@ -37,7 +37,11 @@ const SCAN: ScanSpec = {
|
|
|
37
37
|
const EXCLUDE = /(\.d\.(ts|tsx)$|\/dist\/)/;
|
|
38
38
|
const COMMENT_MARKER_PREFIX_RE = /^\s*(?:\/\/+|\/\*+|\*+)?\s*/;
|
|
39
39
|
const COMMENT_CLOSE_SUFFIX_RE = /\s*\*\/\s*\}?\s*$/;
|
|
40
|
-
|
|
40
|
+
// Not anchored: lineHasIgnoreTag honours the tag anywhere in a line, so a prefixed tag must be checked too.
|
|
41
|
+
const TAG_LINE_RE = /\bkumiko-lint-ignore\s+(\S+)(?:\s+(.*))?$/;
|
|
42
|
+
// Only the rules that replaced deleted guards inherit the reason check; other biome-ignore rules never had one.
|
|
43
|
+
const BIOME_TAG_LINE_RE =
|
|
44
|
+
/\bbiome-ignore(?:-all|-start)?\s+(lint\/(?:plugin|style\/(?:noProcessEnv|noInlineStyles|noRestrictedImports|noRestrictedGlobals))\S*?)\s*:\s*(.*)$/;
|
|
41
45
|
|
|
42
46
|
export type WeakIgnoreReason = {
|
|
43
47
|
readonly line: number;
|
|
@@ -53,15 +57,25 @@ function isWeakReason(reason: string): boolean {
|
|
|
53
57
|
return isGenericReason(reason) || reason.split(/\s+/).filter(Boolean).length < MIN_REASON_WORDS;
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
function countNewlines(text: string, from: number, to: number): number {
|
|
61
|
+
let count = 0;
|
|
62
|
+
for (let i = text.indexOf("\n", from); i !== -1 && i < to; i = text.indexOf("\n", i + 1)) count++;
|
|
63
|
+
return count;
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
export function findWeakIgnoreReasons(fullText: string): WeakIgnoreReason[] {
|
|
57
67
|
const sites: WeakIgnoreReason[] = [];
|
|
68
|
+
let scannedUpTo = 0;
|
|
69
|
+
let firstLine = 1;
|
|
58
70
|
for (const comment of scanCommentTrivia(fullText)) {
|
|
59
|
-
|
|
71
|
+
firstLine += countNewlines(fullText, scannedUpTo, comment.start);
|
|
72
|
+
scannedUpTo = comment.start;
|
|
60
73
|
for (const [offset, rawLine] of comment.text.split("\n").entries()) {
|
|
61
74
|
const body = rawLine
|
|
62
75
|
.replace(COMMENT_MARKER_PREFIX_RE, "")
|
|
63
76
|
.replace(COMMENT_CLOSE_SUFFIX_RE, "");
|
|
64
|
-
const
|
|
77
|
+
const trimmed = body.trim();
|
|
78
|
+
const match = TAG_LINE_RE.exec(trimmed) ?? BIOME_TAG_LINE_RE.exec(trimmed);
|
|
65
79
|
const slug = match?.[1] ?? "";
|
|
66
80
|
const reason = (match?.[2] ?? "").trim();
|
|
67
81
|
const isCheckable = match !== null && !isPlaceholder(slug) && !isPlaceholder(reason);
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* 2. `runInRowLevelSecurityScope`, `runInSystemRowLevelSecurityScope` and
|
|
7
7
|
* `tenantRowLevelSecurityScope` from `@cosmicdrift/kumiko-testing/helpers` are test-only.
|
|
8
8
|
* 3. `runInSystemRowLevelSecurityScope` and `systemScopedRunner` take a non-empty string literal
|
|
9
|
-
* reason, so every system-scope entry stays greppable
|
|
10
|
-
* framework-internal and only used by an allowlist. An object literal passed to
|
|
9
|
+
* reason, so every system-scope entry stays greppable. An object literal passed to
|
|
11
10
|
* `createTenantDb` with `mode: "system"` carries the same kind of `reason`.
|
|
12
11
|
*
|
|
13
12
|
* Usage:
|
|
@@ -16,8 +15,15 @@
|
|
|
16
15
|
* Exit 1 on violations, 0 when clean.
|
|
17
16
|
*/
|
|
18
17
|
|
|
19
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
type ExportDeclaration,
|
|
20
|
+
type ImportDeclaration,
|
|
21
|
+
Node,
|
|
22
|
+
type SourceFile,
|
|
23
|
+
SyntaxKind,
|
|
24
|
+
} from "ts-morph";
|
|
20
25
|
import { findRepoRootFor } from "./_lib/baseline-compare";
|
|
26
|
+
import { mayContainEscapedLiteral } from "./_lib/escaped-literal";
|
|
21
27
|
import {
|
|
22
28
|
ALL_REPO_KINDS,
|
|
23
29
|
type AstGuard,
|
|
@@ -51,14 +57,6 @@ const REASON_ARG_INDEX: Record<string, number> = {
|
|
|
51
57
|
systemScopedRunner: 1,
|
|
52
58
|
};
|
|
53
59
|
|
|
54
|
-
const FIXED_SCOPE_SYMBOL = "SYSTEM_ROW_LEVEL_SECURITY_SCOPE";
|
|
55
|
-
|
|
56
|
-
const FIXED_SCOPE_ALLOWLIST = [
|
|
57
|
-
/^packages\/framework\/src\/db\/row-level-security-scope\.ts$/,
|
|
58
|
-
/^packages\/framework\/src\/pipeline\/dispatch-scope\.ts$/,
|
|
59
|
-
/^packages\/framework\/src\/db\/migrate-runner\.ts$/,
|
|
60
|
-
];
|
|
61
|
-
|
|
62
60
|
// Exercises the empty-reason rejection, so it passes empty literals on purpose.
|
|
63
61
|
const REASON_RULE_EXEMPT = [
|
|
64
62
|
/^packages\/framework\/src\/db\/__tests__\/row-level-security-scope\.test\.ts$/,
|
|
@@ -76,7 +74,7 @@ type Finding = { line: number; message: string };
|
|
|
76
74
|
// escape could spell a name without its plain text, so any `\u` keeps the walk.
|
|
77
75
|
function mayMention(sf: SourceFile, names: readonly string[]): boolean {
|
|
78
76
|
const text = sf.getFullText();
|
|
79
|
-
return text
|
|
77
|
+
return mayContainEscapedLiteral(text) || names.some((name) => text.includes(name));
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
function isTestFile(rel: string): boolean {
|
|
@@ -99,6 +97,13 @@ function staticSpecifierHead(arg: Node): string | undefined {
|
|
|
99
97
|
return undefined;
|
|
100
98
|
}
|
|
101
99
|
|
|
100
|
+
// `import m = require("x")`
|
|
101
|
+
function requireSpecifierOf(reference: Node): string | undefined {
|
|
102
|
+
if (!Node.isExternalModuleReference(reference)) return undefined;
|
|
103
|
+
const expression = reference.getExpression();
|
|
104
|
+
return expression === undefined ? undefined : staticSpecifierHead(expression);
|
|
105
|
+
}
|
|
106
|
+
|
|
102
107
|
function findInternalImports(sf: SourceFile): Finding[] {
|
|
103
108
|
const findings: Finding[] = [];
|
|
104
109
|
const report = (line: number, specifier: string): void => {
|
|
@@ -113,6 +118,12 @@ function findInternalImports(sf: SourceFile): Finding[] {
|
|
|
113
118
|
report(decl.getStartLineNumber(), specifier);
|
|
114
119
|
}
|
|
115
120
|
}
|
|
121
|
+
for (const decl of sf.getDescendantsOfKind(SyntaxKind.ImportEqualsDeclaration)) {
|
|
122
|
+
const specifier = requireSpecifierOf(decl.getModuleReference());
|
|
123
|
+
if (specifier !== undefined && isInternalSpecifier(specifier)) {
|
|
124
|
+
report(decl.getStartLineNumber(), specifier);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
116
127
|
for (const call of sf.getDescendantsOfKind(SyntaxKind.CallExpression)) {
|
|
117
128
|
const callee = call.getExpression();
|
|
118
129
|
const isDynamicImport = callee.getKind() === SyntaxKind.ImportKeyword;
|
|
@@ -128,6 +139,11 @@ function findInternalImports(sf: SourceFile): Finding[] {
|
|
|
128
139
|
return findings;
|
|
129
140
|
}
|
|
130
141
|
|
|
142
|
+
// `export * from` / `export * as ns from`: no named exports to inspect.
|
|
143
|
+
function isStarReexport(decl: ImportDeclaration | ExportDeclaration): boolean {
|
|
144
|
+
return !("getNamedImports" in decl) && decl.getNamedExports().length === 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
131
147
|
function findTestOnlyScopeImports(sf: SourceFile): Finding[] {
|
|
132
148
|
const findings: Finding[] = [];
|
|
133
149
|
const decls = [
|
|
@@ -136,6 +152,12 @@ function findTestOnlyScopeImports(sf: SourceFile): Finding[] {
|
|
|
136
152
|
];
|
|
137
153
|
for (const decl of decls) {
|
|
138
154
|
if (decl.getModuleSpecifierValue() !== TESTING_HELPERS) continue;
|
|
155
|
+
if (isStarReexport(decl)) {
|
|
156
|
+
findings.push({
|
|
157
|
+
line: decl.getStartLineNumber(),
|
|
158
|
+
message: `[test-only-scope] export * from ${TESTING_HELPERS} re-exports the test-only scope helpers; allowed in test files only`,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
139
161
|
const named =
|
|
140
162
|
"getNamedImports" in decl
|
|
141
163
|
? decl.getNamedImports().map((n) => n.getName())
|
|
@@ -249,21 +271,10 @@ function findTenantDbReasonViolations(sf: SourceFile): Finding[] {
|
|
|
249
271
|
return findings;
|
|
250
272
|
}
|
|
251
273
|
|
|
252
|
-
function findFixedScopeUses(sf: SourceFile): Finding[] {
|
|
253
|
-
if (!sf.getFullText().includes(FIXED_SCOPE_SYMBOL)) return [];
|
|
254
|
-
return sf
|
|
255
|
-
.getDescendantsOfKind(SyntaxKind.Identifier)
|
|
256
|
-
.filter((id) => id.getText() === FIXED_SCOPE_SYMBOL)
|
|
257
|
-
.map((id) => ({
|
|
258
|
-
line: id.getStartLineNumber(),
|
|
259
|
-
message: `[fixed-system-scope] ${FIXED_SCOPE_SYMBOL} carries no call-site reason; use runInSystemRowLevelSecurityScope(reason, fn)`,
|
|
260
|
-
}));
|
|
261
|
-
}
|
|
262
|
-
|
|
263
274
|
export const guard: AstGuard = {
|
|
264
275
|
name: "Internal-Subpath-Imports Guard",
|
|
265
276
|
scan: SCAN,
|
|
266
|
-
hint: "Consumer repos use the public subpaths only; `@cosmicdrift/kumiko-framework/internal/*` is for framework packages. Scope helpers from kumiko-testing/helpers belong in tests. Every system-scope entry, including createTenantDb with mode system, passes a specific string-literal reason (why it needs cross-tenant access).
|
|
277
|
+
hint: "Consumer repos use the public subpaths only; `@cosmicdrift/kumiko-framework/internal/*` is for framework packages. Scope helpers from kumiko-testing/helpers belong in tests. Every system-scope entry, including createTenantDb with mode system, passes a specific string-literal reason (why it needs cross-tenant access).",
|
|
267
278
|
run(files, roots = resolveRepoRoots()) {
|
|
268
279
|
const violations: Array<{ file: string; line: number; message: string }> = [];
|
|
269
280
|
|
|
@@ -278,7 +289,6 @@ export const guard: AstGuard = {
|
|
|
278
289
|
if (!isAllowlisted(rel, FORWARDED_TENANT_DB_REASON_ALLOWLIST)) {
|
|
279
290
|
findings.push(...findTenantDbReasonViolations(sf));
|
|
280
291
|
}
|
|
281
|
-
if (!isAllowlisted(rel, FIXED_SCOPE_ALLOWLIST)) findings.push(...findFixedScopeUses(sf));
|
|
282
292
|
for (const f of findings) violations.push({ file: rel, ...f });
|
|
283
293
|
}
|
|
284
294
|
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import { existsSync, readFileSync } from "node:fs";
|
|
23
23
|
import { Glob } from "bun";
|
|
24
24
|
import { Node, type SourceFile, SyntaxKind } from "ts-morph";
|
|
25
|
+
import { decodedLiteralText, mayContainEscapedLiteral } from "./_lib/escaped-literal";
|
|
25
26
|
import {
|
|
26
27
|
ALL_REPO_KINDS,
|
|
27
28
|
type AstGuard,
|
|
@@ -145,26 +146,67 @@ const MENTIONS_RLS_SETTING_RE = /kumiko\.|set_config/i;
|
|
|
145
146
|
|
|
146
147
|
function findSessionSettings(sf: SourceFile, rel: string) {
|
|
147
148
|
const found: Array<{ line: number; message: string }> = [];
|
|
148
|
-
|
|
149
|
+
const text = sf.getFullText();
|
|
150
|
+
if (!MENTIONS_RLS_SETTING_RE.test(text) && !mayContainEscapedLiteral(text)) return found;
|
|
149
151
|
for (const node of sf.getDescendants()) {
|
|
150
152
|
if (!isStringLike(node)) continue;
|
|
151
153
|
// A template's own spans are visited as separate nodes; its full text is checked once here.
|
|
152
154
|
if (node.getParent()?.getKind() === SyntaxKind.TemplateSpan) continue;
|
|
153
|
-
for (const message of violationsInText(node
|
|
155
|
+
for (const message of violationsInText(decodedLiteralText(node), rel)) {
|
|
154
156
|
found.push({ line: node.getStartLineNumber(), message: `[rls-session-setting] ${message}` });
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
return found;
|
|
158
160
|
}
|
|
159
161
|
|
|
160
|
-
const SQL_IGNORED_DIRS = /(^|\/)(node_modules|\.wt|\.git|dist)(\/|$)/;
|
|
162
|
+
const SQL_IGNORED_DIRS = /(^|\/)(node_modules|\.wt|\.git|\.turbo|dist|build|coverage)(\/|$)/;
|
|
163
|
+
const DOLLAR_QUOTE_OPEN_RE = /^\$(?:[A-Za-z_]\w*)?\$/;
|
|
164
|
+
|
|
165
|
+
function closingIndex(sql: string, token: string, from: number): number {
|
|
166
|
+
const index = sql.indexOf(token, from);
|
|
167
|
+
return index === -1 ? sql.length : index + token.length;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Splits on top-level ";" only. Comments are dropped (their newlines kept for line counting);
|
|
171
|
+
// quoted strings, quoted identifiers and dollar-quoted bodies stay intact and never split.
|
|
172
|
+
function sqlStatements(sql: string): string[] {
|
|
173
|
+
const statements: string[] = [];
|
|
174
|
+
let current = "";
|
|
175
|
+
let i = 0;
|
|
176
|
+
while (i < sql.length) {
|
|
177
|
+
if (sql.startsWith("--", i)) {
|
|
178
|
+
const eol = sql.indexOf("\n", i);
|
|
179
|
+
i = eol === -1 ? sql.length : eol;
|
|
180
|
+
} else if (sql.startsWith("/*", i)) {
|
|
181
|
+
const close = closingIndex(sql, "*/", i + 2);
|
|
182
|
+
current += sql.slice(i, close).replace(/[^\n]/g, "");
|
|
183
|
+
i = close;
|
|
184
|
+
} else if (sql.charAt(i) === ";") {
|
|
185
|
+
statements.push(current);
|
|
186
|
+
current = "";
|
|
187
|
+
i++;
|
|
188
|
+
} else {
|
|
189
|
+
const end = quotedSpanEnd(sql, i) ?? i + 1;
|
|
190
|
+
current += sql.slice(i, end);
|
|
191
|
+
i = end;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
statements.push(current);
|
|
195
|
+
return statements;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function quotedSpanEnd(sql: string, from: number): number | undefined {
|
|
199
|
+
const c = sql.charAt(from);
|
|
200
|
+
if (c === "'" || c === '"') return closingIndex(sql, c, from + 1);
|
|
201
|
+
if (c !== "$" || /\w/.test(sql.charAt(from - 1))) return undefined;
|
|
202
|
+
const tag = DOLLAR_QUOTE_OPEN_RE.exec(sql.slice(from, from + 64))?.[0];
|
|
203
|
+
return tag === undefined ? undefined : closingIndex(sql, tag, from + tag.length);
|
|
204
|
+
}
|
|
161
205
|
|
|
162
|
-
// Statements split on ";" with their start line; "--" comment lines are blanked so prose in them never matches.
|
|
163
206
|
export function findSqlSessionSettings(sql: string, rel: string) {
|
|
164
207
|
const found: Array<{ line: number; message: string }> = [];
|
|
165
|
-
const code = sql.replace(/^\s*--.*$/gm, "");
|
|
166
208
|
let line = 1;
|
|
167
|
-
for (const statement of
|
|
209
|
+
for (const statement of sqlStatements(sql)) {
|
|
168
210
|
const startLine =
|
|
169
211
|
line + countNewlines(statement.slice(0, statement.length - statement.trimStart().length));
|
|
170
212
|
for (const message of violationsInText(statement, rel)) {
|
|
@@ -23,7 +23,7 @@ import { type ScanSpec, scanFiles } from "./_lib/scan-scope";
|
|
|
23
23
|
const SCAN: ScanSpec = { scope: "source", extensions: ["ts"], kinds: ["app", "library"] };
|
|
24
24
|
|
|
25
25
|
const SCHEMA_MODULE_REL = "kumiko/schema.ts";
|
|
26
|
-
const SCHEMA_MODULE_SPECIFIER = /(^|\/)kumiko\/schema(\.
|
|
26
|
+
const SCHEMA_MODULE_SPECIFIER = /(^|\/)kumiko\/schema(\.[cm]?[jt]s)?$/;
|
|
27
27
|
const SCHEMA_CLI_CALL = "runSchemaCli";
|
|
28
28
|
const OPTIONS_ARG_INDEX = 3;
|
|
29
29
|
const FEATURES_EXPORT = "FEATURES";
|
|
@@ -49,6 +49,25 @@ function importOf(sf: SourceFile, localName: string): { name: string; module: st
|
|
|
49
49
|
return undefined;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
function schemaNamespaceImports(sf: SourceFile): Set<string> {
|
|
53
|
+
const names = new Set<string>();
|
|
54
|
+
for (const imp of sf.getImportDeclarations()) {
|
|
55
|
+
const namespace = imp.getNamespaceImport();
|
|
56
|
+
if (namespace !== undefined && SCHEMA_MODULE_SPECIFIER.test(imp.getModuleSpecifierValue())) {
|
|
57
|
+
names.add(namespace.getText());
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return names;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function isSchemaFeaturesNamespaceAccess(sf: SourceFile, value: Node): boolean {
|
|
64
|
+
return (
|
|
65
|
+
Node.isPropertyAccessExpression(value) &&
|
|
66
|
+
value.getName() === FEATURES_EXPORT &&
|
|
67
|
+
schemaNamespaceImports(sf).has(value.getExpression().getText())
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
52
71
|
function isSchemaFeaturesImport(sf: SourceFile, localName: string): boolean {
|
|
53
72
|
const imported = importOf(sf, localName);
|
|
54
73
|
return (
|
|
@@ -73,6 +92,7 @@ function featuresValueOf(options: Node): Node | undefined | "no-literal" {
|
|
|
73
92
|
}
|
|
74
93
|
|
|
75
94
|
function isRunSchemaCliCall(sf: SourceFile, callee: Node): boolean {
|
|
95
|
+
if (Node.isPropertyAccessExpression(callee)) return callee.getName() === SCHEMA_CLI_CALL;
|
|
76
96
|
if (!Node.isIdentifier(callee)) return false;
|
|
77
97
|
const localName = callee.getText();
|
|
78
98
|
return (importOf(sf, localName)?.name ?? localName) === SCHEMA_CLI_CALL;
|
|
@@ -88,6 +108,7 @@ function problemOf(sf: SourceFile, optionsArg: Node | undefined): string | undef
|
|
|
88
108
|
}
|
|
89
109
|
if (value === undefined) return `${SCHEMA_CLI_CALL} options have no \`features\` property`;
|
|
90
110
|
if (Node.isIdentifier(value) && isSchemaFeaturesImport(sf, value.getText())) return undefined;
|
|
111
|
+
if (isSchemaFeaturesNamespaceAccess(sf, value)) return undefined;
|
|
91
112
|
return `${SCHEMA_CLI_CALL} gets \`features: ${snippet(value)}\`, not ${FEATURES_EXPORT} from kumiko/schema`;
|
|
92
113
|
}
|
|
93
114
|
|
|
@@ -28,8 +28,9 @@ const SCAN: ScanSpec = { scope: "tests", extensions: ["ts"], kinds: ["framework"
|
|
|
28
28
|
const ALLOWLIST: readonly RegExp[] = [
|
|
29
29
|
// Home of the helpers.
|
|
30
30
|
/^packages\/testing\/src\//,
|
|
31
|
-
// The guard's own fixtures.
|
|
31
|
+
// The guard's own fixtures and the Biome plugin fixtures of the same rule.
|
|
32
32
|
/^packages\/guards\/src\/__tests__\//,
|
|
33
|
+
/^packages\/framework\/src\/presets\/__tests__\//,
|
|
33
34
|
// Simulates event-less legacy rows for the backfill.
|
|
34
35
|
/^packages\/bundled-features\/src\/user-data-rights\/__tests__\/read-users-rebuild-survives-lifecycle\.integration\.test\.ts$/,
|
|
35
36
|
// Stands in for the handover move, which itself writes directly.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
|
-
* Warns when a `.unsafe(sql, [...])` parameter list holds a JS array
|
|
3
|
+
* Warns when a `.unsafe(sql, [...])` parameter list holds a JS array literal.
|
|
4
4
|
*
|
|
5
5
|
* Bun.SQL binds a JS array parameter as "a,b" on Linux, so `ANY($n)` fails with a
|
|
6
6
|
* malformed array literal in CI while the same call passes on macOS. Pass
|
|
7
7
|
* `toPostgresArrayLiteral(values)` (from `@cosmicdrift/kumiko-framework/db`) and cast the
|
|
8
8
|
* placeholder (`$1::text[]`).
|
|
9
9
|
*
|
|
10
|
-
* Heuristic without type info: only array literals
|
|
10
|
+
* Heuristic without type info: only array literals directly inside the
|
|
11
11
|
* parameter-list literal are reported; array-typed variables pass unnoticed. Warning only.
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -40,6 +40,8 @@ function unwrapExpression(node: Node): Node {
|
|
|
40
40
|
while (
|
|
41
41
|
Node.isAsExpression(current) ||
|
|
42
42
|
Node.isSatisfiesExpression(current) ||
|
|
43
|
+
Node.isNonNullExpression(current) ||
|
|
44
|
+
Node.isTypeAssertion(current) ||
|
|
43
45
|
Node.isParenthesizedExpression(current)
|
|
44
46
|
) {
|
|
45
47
|
current = current.getExpression();
|
|
@@ -63,11 +65,6 @@ export function findUnsafeArrayParams(sf: SourceFile): UnsafeArrayParamFinding[]
|
|
|
63
65
|
line: element.getStartLineNumber(),
|
|
64
66
|
message: `array literal as an unsafe() parameter binds as "a,b" on Linux; ${FIX_HINT}`,
|
|
65
67
|
});
|
|
66
|
-
} else if (Node.isSpreadElement(element)) {
|
|
67
|
-
findings.push({
|
|
68
|
-
line: element.getStartLineNumber(),
|
|
69
|
-
message: `spread in the unsafe() parameter list; if it feeds ANY($n), ${FIX_HINT}`,
|
|
70
|
-
});
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
}
|
package/src/pre-push.sh
CHANGED
|
@@ -90,20 +90,54 @@ has_ui_roots() {
|
|
|
90
90
|
' "$REPO_ROOT/kumiko.json") >/dev/null 2>&1
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
# Re-entry from the wrapping check-wt.sh
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
93
|
+
# Re-entry from the wrapping check-wt.sh needs three proofs, so a freely
|
|
94
|
+
# exported variable can neither skip the tracked check-wt.sh nor the pre-flight
|
|
95
|
+
# steps below: the hook records its PID in KUMIKO_CHECK_WT_OWNER and a random
|
|
96
|
+
# nonce in KUMIKO_CHECK_WT_NONCE plus a 0600 file in the git common dir; the
|
|
97
|
+
# owner must be an ancestor (or this very process, when check-wt.sh exec'd the
|
|
98
|
+
# hook) and an ancestor must be running check-wt.sh.
|
|
99
|
+
prepush_nonce_file() {
|
|
100
|
+
printf '%s/kumiko-prepush-%s' "$GIT_COMMON_DIR" "$1"
|
|
101
|
+
}
|
|
102
|
+
|
|
97
103
|
is_reentry_from_check_wt() {
|
|
98
104
|
reentry_pid=$$
|
|
99
105
|
case "${KUMIKO_CHECK_WT_OWNER:-}" in '' | *[!0-9]*) return 1 ;; esac
|
|
106
|
+
case "${KUMIKO_CHECK_WT_NONCE:-}" in '' | *[!0-9a-f]*) return 1 ;; esac
|
|
107
|
+
stored_nonce=""
|
|
108
|
+
IFS= read -r stored_nonce < "$(prepush_nonce_file "$KUMIKO_CHECK_WT_OWNER")" 2>/dev/null || return 1
|
|
109
|
+
[ "$stored_nonce" = "$KUMIKO_CHECK_WT_NONCE" ] || return 1
|
|
100
110
|
while [ -n "$reentry_pid" ] && [ "$reentry_pid" -gt 1 ]; do
|
|
101
|
-
[ "$reentry_pid" = "$KUMIKO_CHECK_WT_OWNER" ]
|
|
111
|
+
if [ "$reentry_pid" = "$KUMIKO_CHECK_WT_OWNER" ]; then
|
|
112
|
+
# An exec'd check-wt.sh has become this hook, so its command line no longer names the script.
|
|
113
|
+
[ "$reentry_pid" = "$$" ] && return 0
|
|
114
|
+
owner_command=$(ps -o command= -p "$reentry_pid" 2>/dev/null)
|
|
115
|
+
case "$owner_command" in *scripts/check-wt.sh*) return 0 ;; esac
|
|
116
|
+
return 1
|
|
117
|
+
fi
|
|
102
118
|
reentry_pid=$(ps -o ppid= -p "$reentry_pid" 2>/dev/null | tr -d ' ')
|
|
103
119
|
done
|
|
104
120
|
return 1
|
|
105
121
|
}
|
|
106
122
|
|
|
123
|
+
# Nonce files of finished runs are not removed by the exec'd check-wt.sh, so
|
|
124
|
+
# each outer run sweeps the ones whose PID is gone.
|
|
125
|
+
sweep_stale_prepush_nonces() {
|
|
126
|
+
for stale_file in "$GIT_COMMON_DIR"/kumiko-prepush-*; do
|
|
127
|
+
[ -e "$stale_file" ] || continue
|
|
128
|
+
stale_pid=${stale_file##*-}
|
|
129
|
+
case "$stale_pid" in '' | *[!0-9]*) continue ;; esac
|
|
130
|
+
kill -0 "$stale_pid" 2>/dev/null || rm -f "$stale_file"
|
|
131
|
+
done
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
write_prepush_nonce() {
|
|
135
|
+
new_nonce=$(od -An -N16 -tx1 /dev/urandom | tr -d ' \n')
|
|
136
|
+
case "$new_nonce" in '' | *[!0-9a-f]*) return 1 ;; esac
|
|
137
|
+
(umask 077 && printf '%s\n' "$new_nonce" > "$(prepush_nonce_file "$$")") || return 1
|
|
138
|
+
printf '%s' "$new_nonce"
|
|
139
|
+
}
|
|
140
|
+
|
|
107
141
|
CHECK_WT_REENTRY=0
|
|
108
142
|
if is_reentry_from_check_wt; then
|
|
109
143
|
CHECK_WT_REENTRY=1
|
|
@@ -192,7 +226,13 @@ if [ "$CHECK_WT_REENTRY" = 0 ] \
|
|
|
192
226
|
&& git -C "$REPO_ROOT" ls-files --error-unmatch scripts/check-wt.sh >/dev/null 2>&1 \
|
|
193
227
|
&& [ -x "$REPO_ROOT/scripts/check-wt.sh" ]; then
|
|
194
228
|
echo "[pre-push] worktree detected — worktree check (see scripts/check-wt.sh)…"
|
|
195
|
-
|
|
229
|
+
sweep_stale_prepush_nonces
|
|
230
|
+
# Without a recorded nonce the delegated run could not be recognised as re-entry and would loop.
|
|
231
|
+
if ! CHECK_WT_NONCE=$(write_prepush_nonce); then
|
|
232
|
+
echo "[pre-push] FATAL: could not write the re-entry nonce file in '$GIT_COMMON_DIR' — refusing push" >&2
|
|
233
|
+
exit 1
|
|
234
|
+
fi
|
|
235
|
+
cd "$REPO_ROOT" && KUMIKO_CHECK_WT_OWNER=$$ KUMIKO_CHECK_WT_NONCE=$CHECK_WT_NONCE exec "$REPO_ROOT/scripts/check-wt.sh"
|
|
196
236
|
fi
|
|
197
237
|
|
|
198
238
|
# The repo that ships kumiko-guards runs its checked-out cli.ts, so a push checks
|
package/src/run-guards.ts
CHANGED
|
@@ -22,79 +22,51 @@ import { acquireGuardRunSlot } from "./_lib/run-slots";
|
|
|
22
22
|
import { writeSecurityBaselines } from "./_lib/security-baseline-cli";
|
|
23
23
|
import { guard as asCasts } from "./check-as-casts";
|
|
24
24
|
import { guard as complexity } from "./check-complexity";
|
|
25
|
-
import { guard as predicateExtraction } from "./check-predicates";
|
|
26
|
-
import { guard as adminApi } from "./guard-admin-api";
|
|
27
25
|
import { guard as appFeatureStructure } from "./guard-app-feature-structure";
|
|
28
26
|
import { guard as commentIssueRefOnly } from "./guard-comment-issue-ref-only";
|
|
29
27
|
import { guard as crossFeatureImports } from "./guard-cross-feature-imports";
|
|
30
28
|
import { guard as directEntityWrites } from "./guard-direct-entity-writes";
|
|
31
|
-
import { guard as directFetch } from "./guard-direct-fetch";
|
|
32
|
-
import { guard as errorReasons } from "./guard-error-reasons";
|
|
33
|
-
import { guard as eventStoreWrites } from "./guard-event-store-writes";
|
|
34
29
|
import { guard as fakeTests } from "./guard-fake-tests";
|
|
35
30
|
import { guard as fileSize } from "./guard-file-size";
|
|
36
31
|
import { guard as htmlEscape } from "./guard-html-escape";
|
|
37
32
|
import { guard as i18nKeys } from "./guard-i18n-keys";
|
|
38
33
|
import { guard as i18nLocaleMount } from "./guard-i18n-locale-mount";
|
|
39
|
-
import { guard as i18nLocaleTerminology } from "./guard-i18n-locale-terminology";
|
|
40
34
|
import { guard as ignoreTagReason } from "./guard-ignore-tag-reason";
|
|
41
35
|
import { guard as importExtensions } from "./guard-import-extensions";
|
|
42
36
|
import { guard as internalSubpathImports } from "./guard-internal-subpath-imports";
|
|
43
37
|
import { guard as libTestCoverage } from "./guard-lib-test-coverage";
|
|
44
|
-
import { guard as noDateApi } from "./guard-no-date-api";
|
|
45
|
-
import { guard as noDirectFs } from "./guard-no-direct-fs";
|
|
46
38
|
import { guard as noLogicInViews } from "./guard-no-logic-in-views";
|
|
47
|
-
import { guard as noTemporalPolyfillImport } from "./guard-no-temporal-polyfill-import";
|
|
48
|
-
import { guard as restrictedSymbols } from "./guard-restricted-symbols";
|
|
49
39
|
import { guard as rlsSessionSettings } from "./guard-rls-session-settings";
|
|
50
40
|
import { guard as screenConventions } from "./guard-screen-conventions";
|
|
51
|
-
import { guard as silentSkip } from "./guard-silent-skip";
|
|
52
41
|
import { guard as tenantEscalation } from "./guard-tenant-escalation";
|
|
53
|
-
import { guard as testEsFixtures } from "./guard-test-es-fixtures";
|
|
54
42
|
import { guard as testEsRowWrites } from "./guard-test-es-row-writes";
|
|
55
43
|
import { guard as testTemplateDrift } from "./guard-test-template-drift";
|
|
56
44
|
import { guard as testTimeouts } from "./guard-test-timeouts";
|
|
57
|
-
import { guard as testTitle } from "./guard-test-title";
|
|
58
|
-
import { guard as unsafeJsonParse } from "./guard-unsafe-json-parse";
|
|
59
45
|
import { guard as writeHandlerQns } from "./guard-write-handler-qns";
|
|
60
46
|
|
|
61
47
|
export const GUARDS = [
|
|
62
|
-
adminApi,
|
|
63
48
|
directEntityWrites,
|
|
64
|
-
directFetch,
|
|
65
|
-
noDirectFs,
|
|
66
49
|
tenantEscalation,
|
|
67
|
-
unsafeJsonParse,
|
|
68
|
-
silentSkip,
|
|
69
50
|
htmlEscape,
|
|
70
51
|
importExtensions,
|
|
71
52
|
crossFeatureImports,
|
|
72
|
-
noDateApi,
|
|
73
|
-
noTemporalPolyfillImport,
|
|
74
|
-
restrictedSymbols,
|
|
75
53
|
internalSubpathImports,
|
|
76
54
|
rlsSessionSettings,
|
|
77
55
|
fakeTests,
|
|
78
56
|
noLogicInViews,
|
|
79
|
-
errorReasons,
|
|
80
57
|
i18nKeys,
|
|
81
58
|
i18nLocaleMount,
|
|
82
|
-
i18nLocaleTerminology,
|
|
83
59
|
complexity,
|
|
84
|
-
predicateExtraction,
|
|
85
60
|
screenConventions,
|
|
86
61
|
writeHandlerQns,
|
|
87
62
|
asCasts,
|
|
88
|
-
eventStoreWrites,
|
|
89
63
|
appFeatureStructure,
|
|
90
64
|
libTestCoverage,
|
|
91
65
|
testTimeouts,
|
|
92
|
-
testEsFixtures,
|
|
93
66
|
testEsRowWrites,
|
|
94
67
|
testTemplateDrift,
|
|
95
68
|
fileSize,
|
|
96
69
|
commentIssueRefOnly,
|
|
97
|
-
testTitle,
|
|
98
70
|
ignoreTagReason,
|
|
99
71
|
];
|
|
100
72
|
|
package/src/run-repo-checks.ts
CHANGED
|
@@ -13,22 +13,16 @@ import { check as appDockerfile } from "./guard-app-dockerfile";
|
|
|
13
13
|
import { check as docStatus } from "./guard-doc-status";
|
|
14
14
|
import { check as featureIntegrationTests } from "./guard-feature-integration-tests";
|
|
15
15
|
import { check as guardsDocDrift } from "./guard-guards-doc-drift";
|
|
16
|
-
import { check as noDirectProcessEnv } from "./guard-no-direct-process-env";
|
|
17
|
-
import { check as primitivesDiscipline } from "./guard-primitives-discipline";
|
|
18
16
|
import { check as rawSql } from "./guard-raw-sql";
|
|
19
17
|
import { check as rendererBoundaries } from "./guard-renderer-boundaries";
|
|
20
18
|
import { check as schemaCliFeatures } from "./guard-schema-cli-features";
|
|
21
19
|
import { check as testStackDrift } from "./guard-test-stack-drift";
|
|
22
|
-
import { check as thinWrappers } from "./guard-thin-wrappers";
|
|
23
20
|
import { check as unsafeArrayParam } from "./guard-unsafe-array-param";
|
|
24
21
|
import { check as upgradeState } from "./guard-upgrade-state";
|
|
25
22
|
|
|
26
23
|
export const REPO_CHECKS = [
|
|
27
24
|
rawSql,
|
|
28
|
-
noDirectProcessEnv,
|
|
29
25
|
rendererBoundaries,
|
|
30
|
-
primitivesDiscipline,
|
|
31
|
-
thinWrappers,
|
|
32
26
|
secretLiterals,
|
|
33
27
|
featureIntegrationTests,
|
|
34
28
|
testStackDrift,
|
|
@@ -35,10 +35,10 @@ export function parseStepArgs(argv: readonly string[]): ParsedArgs {
|
|
|
35
35
|
return { failPrefix, lanes };
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
const MIN_POOL =
|
|
38
|
+
// The pool follows the free capacity (cores minus 1-min load). The floor stays small
|
|
39
|
+
// because the test lane already fans out into its own workers; several pushes at once
|
|
40
|
+
// must not each claim four more lanes on a saturated machine.
|
|
41
|
+
const MIN_POOL = 2;
|
|
42
42
|
|
|
43
43
|
export function resolvePoolSize(
|
|
44
44
|
override: string | undefined,
|
package/src/run-ui-guards.ts
CHANGED
|
@@ -9,24 +9,10 @@ import {
|
|
|
9
9
|
runGuards,
|
|
10
10
|
} from "./_lib/guard-kit";
|
|
11
11
|
import { guard as i18nUiStrings } from "./guard-i18n-ui-strings";
|
|
12
|
-
import { guard as noCustomPrimitives } from "./guard-no-custom-primitives";
|
|
13
12
|
import { guard as noFramedExtensionSections } from "./guard-no-framed-extension-sections";
|
|
14
|
-
import { guard as noInlineStyles } from "./guard-no-inline-styles";
|
|
15
|
-
import { guard as noRawHooks } from "./guard-no-raw-hooks";
|
|
16
|
-
import { guard as rawClassname } from "./guard-raw-classname";
|
|
17
|
-
import { guard as rawInteractiveElements } from "./guard-raw-interactive-elements";
|
|
18
13
|
import { guard as tailwindScanSurface } from "./guard-tailwind-scan-surface";
|
|
19
14
|
|
|
20
|
-
export const UI_GUARDS = [
|
|
21
|
-
rawClassname,
|
|
22
|
-
noInlineStyles,
|
|
23
|
-
noCustomPrimitives,
|
|
24
|
-
noFramedExtensionSections,
|
|
25
|
-
noRawHooks,
|
|
26
|
-
tailwindScanSurface,
|
|
27
|
-
rawInteractiveElements,
|
|
28
|
-
i18nUiStrings,
|
|
29
|
-
];
|
|
15
|
+
export const UI_GUARDS = [noFramedExtensionSections, tailwindScanSurface, i18nUiStrings];
|
|
30
16
|
|
|
31
17
|
// No flags today — the array stays so an unknown flag still fails loud
|
|
32
18
|
// instead of silently doing nothing, and so a future flag has one place to land.
|