@cosmicdrift/kumiko-guards 0.413.0 → 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.
Files changed (52) hide show
  1. package/README.md +15 -9
  2. package/package.json +4 -4
  3. package/src/_lib/agent-docs-api-nodes.ts +9 -2
  4. package/src/_lib/agent-docs-api-render.ts +31 -10
  5. package/src/_lib/agent-docs-api.ts +13 -9
  6. package/src/_lib/agent-docs-feature-imports.ts +12 -1
  7. package/src/_lib/baseline-compare.ts +1 -2
  8. package/src/_lib/doc-status.ts +8 -4
  9. package/src/_lib/dockerfile.ts +28 -5
  10. package/src/_lib/escaped-literal.ts +26 -0
  11. package/src/_lib/npm-registry.ts +2 -2
  12. package/src/_lib/run-slots.ts +4 -6
  13. package/src/_lib/security-audit.ts +22 -6
  14. package/src/_lib/test-es-raw-writes.ts +5 -3
  15. package/src/changes.json +44 -0
  16. package/src/check-security.ts +4 -3
  17. package/src/guard-app-dockerfile.ts +29 -12
  18. package/src/guard-ignore-tag-reason.ts +18 -4
  19. package/src/guard-internal-subpath-imports.ts +35 -25
  20. package/src/guard-rls-session-settings.ts +48 -6
  21. package/src/guard-schema-cli-features.ts +22 -1
  22. package/src/guard-test-es-row-writes.ts +2 -1
  23. package/src/guard-unsafe-array-param.ts +4 -7
  24. package/src/pre-push.sh +46 -6
  25. package/src/run-guards.ts +0 -28
  26. package/src/run-repo-checks.ts +0 -6
  27. package/src/run-steps-parallel.ts +4 -4
  28. package/src/run-ui-guards.ts +1 -15
  29. package/src/_lib/german-test-title.ts +0 -94
  30. package/src/_lib/primitives-access.ts +0 -23
  31. package/src/check-predicates.ts +0 -244
  32. package/src/guard-admin-api.ts +0 -138
  33. package/src/guard-direct-fetch.ts +0 -161
  34. package/src/guard-error-reasons.ts +0 -210
  35. package/src/guard-event-store-writes.ts +0 -124
  36. package/src/guard-i18n-locale-terminology.ts +0 -134
  37. package/src/guard-no-custom-primitives.ts +0 -193
  38. package/src/guard-no-date-api.ts +0 -183
  39. package/src/guard-no-direct-fs.ts +0 -346
  40. package/src/guard-no-direct-process-env.ts +0 -127
  41. package/src/guard-no-inline-styles.ts +0 -64
  42. package/src/guard-no-raw-hooks.ts +0 -80
  43. package/src/guard-no-temporal-polyfill-import.ts +0 -131
  44. package/src/guard-primitives-discipline.ts +0 -357
  45. package/src/guard-raw-classname.ts +0 -117
  46. package/src/guard-raw-interactive-elements.ts +0 -164
  47. package/src/guard-restricted-symbols.ts +0 -155
  48. package/src/guard-silent-skip.ts +0 -186
  49. package/src/guard-test-es-fixtures.ts +0 -85
  50. package/src/guard-test-title.ts +0 -159
  51. package/src/guard-thin-wrappers.ts +0 -471
  52. package/src/guard-unsafe-json-parse.ts +0 -87
@@ -1,85 +0,0 @@
1
- #!/usr/bin/env bun
2
- /**
3
- * Guard: tests seed event-sourced state through the event store, not through
4
- * hand-written SQL. Flags, in test files, string/template literals with
5
- * (a) INSERT INTO / UPDATE against kumiko_events (use append / runSeedWritesAt)
6
- * (b) CREATE TABLE ... read_tenant_memberships (use unsafeCreateEntityTable with
7
- * tenantMembershipEntity and seedRow, so the schema cannot drift from the entity)
8
- *
9
- * Usage:
10
- * bun packages/guards/src/guard-test-es-fixtures.ts
11
- */
12
- import type { SourceFile } from "ts-morph";
13
- import { SyntaxKind } from "ts-morph";
14
- import {
15
- type AstGuard,
16
- type GuardViolation,
17
- relFromRepoRoot,
18
- runStandalone,
19
- type ScanSpec,
20
- } from "./_lib/guard-kit";
21
- import { type RepoRoot, resolveRepoRoots } from "./_lib/roots";
22
-
23
- const SCAN: ScanSpec = { scope: "tests", extensions: ["ts"] };
24
-
25
- // Bulk seeding of thousands of events through append() would take minutes; these
26
- // perf tests measure the read path on a finished stream, not the seed phase.
27
- // The concurrent-commit ordering tests hold a transaction open and need explicit event
28
- // ids/versions, which append() does not expose.
29
- // The guards' own tests carry the forbidden SQL as fixture strings.
30
- const ALLOWLIST: readonly RegExp[] = [
31
- /^packages\/framework\/src\/event-store\/__tests__\/perf\.integration\.test\.ts$/,
32
- /^packages\/framework\/src\/pipeline\/__tests__\/perf-rebuild\.integration\.test\.ts$/,
33
- /^packages\/framework\/src\/pipeline\/__tests__\/event-dispatcher-commit-order\.integration\.test\.ts$/,
34
- /^packages\/framework\/src\/pipeline\/__tests__\/event-dispatcher-start-from\.integration\.test\.ts$/,
35
- /^packages\/framework\/src\/pipeline\/__tests__\/msp-rebuild\.integration\.test\.ts$/,
36
- /^packages\/framework\/src\/pipeline\/__tests__\/projection-rebuild\.integration\.test\.ts$/,
37
- /^packages\/guards\/src\/__tests__\//,
38
- ];
39
-
40
- const EVENT_WRITE_RE = /\b(INSERT\s+INTO|UPDATE)\s+["`]?kumiko_events\b/i;
41
- const MEMBERSHIP_DDL_RE = /\bCREATE\s+TABLE\b[^;]*?\bread_tenant_memberships\b/i;
42
-
43
- const LITERAL_KINDS = [
44
- SyntaxKind.StringLiteral,
45
- SyntaxKind.NoSubstitutionTemplateLiteral,
46
- SyntaxKind.TemplateExpression,
47
- ];
48
-
49
- function violationMessage(text: string): string | undefined {
50
- const write = EVENT_WRITE_RE.exec(text);
51
- if (write)
52
- return `raw ${write[0].replace(/\s+/g, " ")} in a test: seed via append() or runSeedWritesAt()`;
53
- if (MEMBERSHIP_DDL_RE.test(text)) {
54
- return "hand-written read_tenant_memberships DDL in a test: use unsafeCreateEntityTable(db, tenantMembershipEntity)";
55
- }
56
- return undefined;
57
- }
58
-
59
- function collect(sourceFile: SourceFile, roots: readonly RepoRoot[]): GuardViolation[] {
60
- const file = relFromRepoRoot(sourceFile.getFilePath(), roots);
61
- if (ALLOWLIST.some((re) => re.test(file))) return [];
62
- // Both rules need one of these table names in a literal, which is part of the file's text.
63
- if (!/kumiko_events|read_tenant_memberships/i.test(sourceFile.getFullText())) return [];
64
- const violations: GuardViolation[] = [];
65
- for (const kind of LITERAL_KINDS) {
66
- for (const node of sourceFile.getDescendantsOfKind(kind)) {
67
- const message = violationMessage(node.getText());
68
- if (message) violations.push({ file, line: node.getStartLineNumber(), message });
69
- }
70
- }
71
- return violations;
72
- }
73
-
74
- export const guard: AstGuard = {
75
- name: "Test-ES-Fixtures Guard",
76
- scan: SCAN,
77
- hint:
78
- "Seed events with append() (runSeedWritesAt for backdating) and membership rows with " +
79
- "seedRow on a table made by unsafeCreateEntityTable; bulk perf seeds belong in the guard allowlist with a Why.",
80
- run(files, roots: readonly RepoRoot[] = resolveRepoRoots()) {
81
- return { violations: files.flatMap((sf) => collect(sf, roots)) };
82
- },
83
- };
84
-
85
- if (import.meta.main) runStandalone(guard);
@@ -1,159 +0,0 @@
1
- #!/usr/bin/env bun
2
- /**
3
- * Test-title guard: the title of a `test`/`it`/`describe` (including `.each`, `.skip`, `.only`,
4
- * `.todo` and `.if` chains) is English and carries no issue or PR reference. A German title or one
5
- * ending in `(#1234)` ages into noise: the number belongs in the commit message, the title has to
6
- * state the behaviour. Existing hits are frozen per file in `.kumiko-test-title-baseline.json` and
7
- * may not grow; without a baseline file (consumer repos) the guard only warns.
8
- */
9
-
10
- import path from "node:path";
11
- import { type CallExpression, Node, type SourceFile, SyntaxKind } from "ts-morph";
12
- import { isGermanTestTitle } from "./_lib/german-test-title";
13
- import {
14
- ALL_REPO_KINDS,
15
- type AstGuard,
16
- baselineRatchet,
17
- buildSharedProject,
18
- filesForGuard,
19
- isLocalFinding,
20
- relFromRepoRoot,
21
- runStandalone,
22
- type ScanSpec,
23
- } from "./_lib/guard-kit";
24
- import { hasIgnoreTag } from "./_lib/ignore-tag";
25
- import { resolveRepoRoots } from "./_lib/roots";
26
- import {
27
- canonicalCalleeText,
28
- declarationBaseCallee,
29
- TEST_DECLARATION_CALLEE,
30
- testFrameworkAliases,
31
- } from "./_lib/test-callee";
32
- import { REFERENCE_RE } from "./guard-comment-issue-ref-only";
33
-
34
- const ROOT = process.cwd();
35
- const GUARD_NAME = "test-title";
36
- const IGNORE_TAG = `kumiko-lint-ignore ${GUARD_NAME}`;
37
-
38
- // Playwright specs sit outside every manifest's testGlobs; so do bin and sample-app tests.
39
- const SCAN: ScanSpec = {
40
- scope: "tests",
41
- kinds: ALL_REPO_KINDS,
42
- extensions: ["ts", "tsx"],
43
- extraGlobs: [
44
- "packages/*/src/**/__tests__/**/*.{ts,tsx}",
45
- "packages/*/bin/**/__tests__/**/*.{ts,tsx}",
46
- "samples/apps/**/*.{test,spec}.{ts,tsx}",
47
- "samples/apps/**/__tests__/**/*.{ts,tsx}",
48
- "e2e/**/*.{ts,tsx}",
49
- "packages/*/e2e/**/*.{ts,tsx}",
50
- "packages/*/src/e2e/**/*.{ts,tsx}",
51
- "samples/e2e/**/*.{ts,tsx}",
52
- "samples/recipes/*/e2e/**/*.{ts,tsx}",
53
- "samples/apps/*/e2e/**/*.{ts,tsx}",
54
- ],
55
- };
56
-
57
- const EXCLUDE = /(\.d\.(ts|tsx)$|\/dist\/)/;
58
- const PLAYWRIGHT_DESCRIBE_CALLEE = /^test\.(describe|fixme|fail)(\.\w+)*$/;
59
-
60
- type TitleFinding = { readonly line: number; readonly title: string; readonly reason: string };
61
-
62
- export function hasIssueReference(title: string): boolean {
63
- return (title.match(REFERENCE_RE)?.length ?? 0) > 0;
64
- }
65
-
66
- function titleReason(title: string): string | undefined {
67
- if (isGermanTestTitle(title)) return "German";
68
- if (hasIssueReference(title)) return "issue reference";
69
- return undefined;
70
- }
71
-
72
- function isTitleLiteral(arg: Node): boolean {
73
- return (
74
- Node.isStringLiteral(arg) ||
75
- Node.isNoSubstitutionTemplateLiteral(arg) ||
76
- Node.isTemplateExpression(arg)
77
- );
78
- }
79
-
80
- function titleLiteralText(arg: Node | undefined): string | undefined {
81
- if (arg === undefined || !isTitleLiteral(arg)) return undefined;
82
- return arg.getText().slice(1, -1);
83
- }
84
-
85
- function isTestDeclaration(call: CallExpression, aliases: ReadonlyMap<string, string>): boolean {
86
- const base = canonicalCalleeText(declarationBaseCallee(call.getExpression()).getText(), aliases);
87
- return TEST_DECLARATION_CALLEE.test(base) || PLAYWRIGHT_DESCRIBE_CALLEE.test(base);
88
- }
89
-
90
- export function findBadTestTitles(sf: SourceFile): TitleFinding[] {
91
- const aliases = testFrameworkAliases(sf);
92
- const findings: TitleFinding[] = [];
93
- for (const call of sf.getDescendantsOfKind(SyntaxKind.CallExpression)) {
94
- if (!isTestDeclaration(call, aliases)) continue;
95
- const arg = call.getArguments()[0];
96
- const title = titleLiteralText(arg);
97
- if (arg === undefined || title === undefined) continue;
98
- const reason = titleReason(title);
99
- if (reason === undefined) continue;
100
- if (hasIgnoreTag(arg, IGNORE_TAG) || hasIgnoreTag(call, IGNORE_TAG)) continue;
101
- findings.push({ line: arg.getStartLineNumber(), title, reason });
102
- }
103
- return findings.sort((a, b) => a.line - b.line);
104
- }
105
-
106
- export function testTitleCounts(
107
- files: readonly SourceFile[],
108
- roots: ReadonlyArray<{ readonly absPath: string }> = resolveRepoRoots(),
109
- ): { counts: Record<string, number>; firstLine: Record<string, number> } {
110
- const counts: Record<string, number> = {};
111
- const firstLine: Record<string, number> = {};
112
- for (const sf of files) {
113
- if (EXCLUDE.test(sf.getFilePath())) continue;
114
- const findings = findBadTestTitles(sf);
115
- const first = findings[0];
116
- if (first === undefined) continue;
117
- const file = relFromRepoRoot(sf.getFilePath(), roots);
118
- if (!isLocalFinding({ file })) continue;
119
- counts[file] = findings.length;
120
- firstLine[file] = first.line;
121
- }
122
- return { counts, firstLine };
123
- }
124
-
125
- const testTitleBaseline = baselineRatchet({
126
- file: path.join(ROOT, ".kumiko-test-title-baseline.json"),
127
- formatVersion: 1,
128
- unit: "German or issue-referencing test title(s)",
129
- });
130
-
131
- const REMEDIATION =
132
- "Write the title in English and state the behaviour instead of the issue number; the number belongs in the commit message.";
133
-
134
- export const guard: AstGuard = {
135
- name: GUARD_NAME,
136
- scan: SCAN,
137
- hint: `after fixing hits: \`kumiko-guards guards --write-baseline --guard=${GUARD_NAME}\`; deliberate exception (e.g. a German fixture string): // ${IGNORE_TAG} <reason>`,
138
- run: (files, roots = resolveRepoRoots()) => {
139
- const { counts, firstLine } = testTitleCounts(files, roots);
140
- return {
141
- violations: testTitleBaseline.check(counts, REMEDIATION, {
142
- formatDriftRemediation: `Run \`kumiko-guards guards --write-baseline --guard=${GUARD_NAME}\` once.`,
143
- resolveLine: (file) => firstLine[file] ?? 1,
144
- }),
145
- };
146
- },
147
- writeBaseline: (files, roots = resolveRepoRoots()) => {
148
- testTitleBaseline.write(testTitleCounts(files, roots).counts);
149
- },
150
- };
151
-
152
- if (import.meta.main) {
153
- if (process.argv.slice(2).includes("--write-baseline")) {
154
- const project = buildSharedProject([guard]);
155
- guard.writeBaseline?.(filesForGuard(project, guard));
156
- process.exit(0);
157
- }
158
- runStandalone(guard);
159
- }