@ontrails/warden 1.0.0-beta.3 → 1.0.0-beta.30
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/CHANGELOG.md +625 -9
- package/README.md +111 -26
- package/bin/warden.ts +50 -0
- package/package.json +28 -5
- package/src/adapter-check.ts +136 -0
- package/src/ast.ts +137 -0
- package/src/cli.ts +1415 -104
- package/src/command.ts +943 -0
- package/src/config.ts +184 -0
- package/src/draft.ts +22 -0
- package/src/drift.ts +122 -22
- package/src/fix.ts +120 -0
- package/src/formatters.ts +79 -9
- package/src/guide.ts +245 -0
- package/src/index.ts +215 -14
- package/src/project-context.ts +163 -0
- package/src/project-rules.ts +290 -0
- package/src/resolve.ts +531 -0
- package/src/rules/activation-orphan.ts +97 -0
- package/src/rules/ast.ts +4008 -86
- package/src/rules/circular-refs.ts +154 -0
- package/src/rules/cli-command-route-coherence.ts +177 -0
- package/src/rules/composes-declarations.ts +837 -0
- package/src/rules/context-no-surface-types.ts +78 -15
- package/src/rules/contour-exists.ts +251 -0
- package/src/rules/contour-ids.ts +15 -0
- package/src/rules/dead-internal-trail.ts +161 -0
- package/src/rules/dead-public-trail.ts +258 -0
- package/src/rules/draft-file-marking.ts +160 -0
- package/src/rules/draft-visible-debt.ts +87 -0
- package/src/rules/duplicate-public-contract.ts +91 -0
- package/src/rules/error-mapping-completeness.ts +290 -0
- package/src/rules/example-valid.ts +395 -0
- package/src/rules/fires-declarations.ts +735 -0
- package/src/rules/implementation-returns-result.ts +1411 -166
- package/src/rules/incomplete-accessor-for-standard-op.ts +272 -0
- package/src/rules/incomplete-crud.ts +581 -0
- package/src/rules/index.ts +234 -18
- package/src/rules/intent-propagation.ts +127 -0
- package/src/rules/layer-field-name-drift.ts +102 -0
- package/src/rules/library-projection-coherence.ts +100 -0
- package/src/rules/metadata.ts +755 -0
- package/src/rules/missing-reconcile.ts +98 -0
- package/src/rules/missing-visibility.ts +110 -0
- package/src/rules/no-destructured-compose.ts +194 -0
- package/src/rules/no-dev-permit-in-source.ts +99 -0
- package/src/rules/no-direct-implementation-call.ts +7 -7
- package/src/rules/no-legacy-layer-imports.ts +211 -0
- package/src/rules/no-native-error-result.ts +118 -0
- package/src/rules/no-redundant-result-error-wrap.ts +384 -0
- package/src/rules/no-retired-cross-vocabulary.ts +194 -0
- package/src/rules/no-sync-result-assumption.ts +1135 -98
- package/src/rules/no-throw-in-detour-recover.ts +225 -0
- package/src/rules/no-throw-in-implementation.ts +10 -9
- package/src/rules/no-top-level-surface.ts +371 -0
- package/src/rules/on-references-exist.ts +194 -0
- package/src/rules/orphaned-signal.ts +150 -0
- package/src/rules/owner-projection-parity.ts +143 -0
- package/src/rules/permit-governance.ts +25 -0
- package/src/rules/public-export-example-coverage.ts +562 -0
- package/src/rules/public-internal-deep-imports.ts +517 -0
- package/src/rules/public-output-schema.ts +29 -0
- package/src/rules/public-union-output-discriminants.ts +150 -0
- package/src/rules/read-intent-fires.ts +187 -0
- package/src/rules/reference-exists.ts +98 -0
- package/src/rules/registry-names.ts +155 -0
- package/src/rules/resolved-import-boundary.ts +146 -0
- package/src/rules/resource-declarations.ts +693 -0
- package/src/rules/resource-exists.ts +179 -0
- package/src/rules/resource-id-grammar.ts +65 -0
- package/src/rules/resource-mock-coverage.ts +115 -0
- package/src/rules/scan.ts +38 -25
- package/src/rules/scheduled-destroy-intent.ts +44 -0
- package/src/rules/signal-graph-coaching.ts +191 -0
- package/src/rules/specs.ts +9 -5
- package/src/rules/static-resource-accessor-preference.ts +649 -0
- package/src/rules/surface-facet-coherence.ts +362 -0
- package/src/rules/trail-fork-coaching.ts +616 -0
- package/src/rules/trail-versioning-source.ts +1072 -0
- package/src/rules/trail-versioning-topo.ts +172 -0
- package/src/rules/types.ts +272 -6
- package/src/rules/unmaterialized-activation-source.ts +84 -0
- package/src/rules/unreachable-detour-shadowing.ts +339 -0
- package/src/rules/valid-describe-refs.ts +162 -32
- package/src/rules/valid-detour-contract.ts +78 -0
- package/src/rules/warden-export-symmetry.ts +540 -0
- package/src/rules/warden-rules-use-ast.ts +1114 -0
- package/src/rules/webhook-route-collision.ts +243 -0
- package/src/trails/activation-orphan.trail.ts +84 -0
- package/src/trails/circular-refs.trail.ts +29 -0
- package/src/trails/cli-command-route-coherence.trail.ts +47 -0
- package/src/trails/composes-declarations.trail.ts +22 -0
- package/src/trails/context-no-surface-types.trail.ts +21 -0
- package/src/trails/contour-exists.trail.ts +21 -0
- package/src/trails/dead-internal-trail.trail.ts +26 -0
- package/src/trails/dead-public-trail.trail.ts +31 -0
- package/src/trails/deprecation-without-guidance.trail.ts +21 -0
- package/src/trails/draft-file-marking.trail.ts +16 -0
- package/src/trails/draft-visible-debt.trail.ts +16 -0
- package/src/trails/duplicate-public-contract.trail.ts +47 -0
- package/src/trails/error-mapping-completeness.trail.ts +30 -0
- package/src/trails/example-valid.trail.ts +25 -0
- package/src/trails/fires-declarations.trail.ts +23 -0
- package/src/trails/fork-without-preserved-blaze.trail.ts +31 -0
- package/src/trails/implementation-returns-result.trail.ts +20 -0
- package/src/trails/incomplete-accessor-for-standard-op.trail.ts +76 -0
- package/src/trails/incomplete-crud.trail.ts +39 -0
- package/src/trails/index.ts +83 -0
- package/src/trails/intent-propagation.trail.ts +30 -0
- package/src/trails/layer-field-name-drift.trail.ts +39 -0
- package/src/trails/library-projection-coherence.trail.ts +43 -0
- package/src/trails/marker-schema-unsupported.trail.ts +23 -0
- package/src/trails/missing-reconcile.trail.ts +33 -0
- package/src/trails/missing-visibility.trail.ts +22 -0
- package/src/trails/no-destructured-compose.trail.ts +44 -0
- package/src/trails/no-dev-permit-in-source.trail.ts +16 -0
- package/src/trails/no-direct-implementation-call.trail.ts +16 -0
- package/src/trails/no-legacy-layer-imports.trail.ts +41 -0
- package/src/trails/no-native-error-result.trail.ts +18 -0
- package/src/trails/no-redundant-result-error-wrap.trail.ts +55 -0
- package/src/trails/no-retired-cross-vocabulary.trail.ts +42 -0
- package/src/trails/no-sync-result-assumption.trail.ts +19 -0
- package/src/trails/no-throw-in-detour-recover.trail.ts +24 -0
- package/src/trails/no-throw-in-implementation.trail.ts +20 -0
- package/src/trails/no-top-level-surface.trail.ts +43 -0
- package/src/trails/on-references-exist.trail.ts +21 -0
- package/src/trails/orphaned-signal.trail.ts +36 -0
- package/src/trails/owner-projection-parity.trail.ts +26 -0
- package/src/trails/pending-force.trail.ts +21 -0
- package/src/trails/permit-governance.trail.ts +51 -0
- package/src/trails/prefer-schema-inference.trail.ts +21 -0
- package/src/trails/public-export-example-coverage.trail.ts +16 -0
- package/src/trails/public-internal-deep-imports.trail.ts +94 -0
- package/src/trails/public-output-schema.trail.ts +55 -0
- package/src/trails/public-union-output-discriminants.trail.ts +33 -0
- package/src/trails/read-intent-fires.trail.ts +20 -0
- package/src/trails/reference-exists.trail.ts +25 -0
- package/src/trails/resolved-import-boundary.trail.ts +109 -0
- package/src/trails/resource-declarations.trail.ts +25 -0
- package/src/trails/resource-exists.trail.ts +27 -0
- package/src/trails/resource-id-grammar.trail.ts +39 -0
- package/src/trails/resource-mock-coverage.trail.ts +40 -0
- package/src/trails/run.ts +162 -0
- package/src/trails/scheduled-destroy-intent.trail.ts +56 -0
- package/src/trails/schema.ts +198 -0
- package/src/trails/signal-graph-coaching.trail.ts +77 -0
- package/src/trails/static-resource-accessor-preference.trail.ts +25 -0
- package/src/trails/surface-facet-coherence.trail.ts +25 -0
- package/src/trails/topo.ts +6 -0
- package/src/trails/trail-fork-coaching.trail.ts +42 -0
- package/src/trails/unmaterialized-activation-source.trail.ts +72 -0
- package/src/trails/unreachable-detour-shadowing.trail.ts +45 -0
- package/src/trails/valid-describe-refs.trail.ts +18 -0
- package/src/trails/valid-detour-contract.trail.ts +71 -0
- package/src/trails/version-gap.trail.ts +35 -0
- package/src/trails/version-pinned-compose.trail.ts +23 -0
- package/src/trails/version-without-examples.trail.ts +38 -0
- package/src/trails/warden-export-symmetry.trail.ts +16 -0
- package/src/trails/warden-rules-use-ast.trail.ts +64 -0
- package/src/trails/webhook-route-collision.trail.ts +50 -0
- package/src/trails/wrap-rule.ts +214 -0
- package/src/workspaces.ts +238 -0
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/dist/cli.d.ts +0 -46
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -221
- package/dist/cli.js.map +0 -1
- package/dist/drift.d.ts +0 -26
- package/dist/drift.d.ts.map +0 -1
- package/dist/drift.js +0 -27
- package/dist/drift.js.map +0 -1
- package/dist/formatters.d.ts +0 -29
- package/dist/formatters.d.ts.map +0 -1
- package/dist/formatters.js +0 -87
- package/dist/formatters.js.map +0 -1
- package/dist/index.d.ts +0 -26
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -26
- package/dist/index.js.map +0 -1
- package/dist/rules/ast.d.ts +0 -41
- package/dist/rules/ast.d.ts.map +0 -1
- package/dist/rules/ast.js +0 -163
- package/dist/rules/ast.js.map +0 -1
- package/dist/rules/context-no-surface-types.d.ts +0 -12
- package/dist/rules/context-no-surface-types.d.ts.map +0 -1
- package/dist/rules/context-no-surface-types.js +0 -96
- package/dist/rules/context-no-surface-types.js.map +0 -1
- package/dist/rules/implementation-returns-result.d.ts +0 -13
- package/dist/rules/implementation-returns-result.d.ts.map +0 -1
- package/dist/rules/implementation-returns-result.js +0 -277
- package/dist/rules/implementation-returns-result.js.map +0 -1
- package/dist/rules/index.d.ts +0 -22
- package/dist/rules/index.d.ts.map +0 -1
- package/dist/rules/index.js +0 -41
- package/dist/rules/index.js.map +0 -1
- package/dist/rules/no-direct-impl-in-route.d.ts +0 -12
- package/dist/rules/no-direct-impl-in-route.d.ts.map +0 -1
- package/dist/rules/no-direct-impl-in-route.js +0 -46
- package/dist/rules/no-direct-impl-in-route.js.map +0 -1
- package/dist/rules/no-direct-implementation-call.d.ts +0 -12
- package/dist/rules/no-direct-implementation-call.d.ts.map +0 -1
- package/dist/rules/no-direct-implementation-call.js +0 -39
- package/dist/rules/no-direct-implementation-call.js.map +0 -1
- package/dist/rules/no-sync-result-assumption.d.ts +0 -6
- package/dist/rules/no-sync-result-assumption.d.ts.map +0 -1
- package/dist/rules/no-sync-result-assumption.js +0 -98
- package/dist/rules/no-sync-result-assumption.js.map +0 -1
- package/dist/rules/no-throw-in-detour-target.d.ts +0 -12
- package/dist/rules/no-throw-in-detour-target.d.ts.map +0 -1
- package/dist/rules/no-throw-in-detour-target.js +0 -87
- package/dist/rules/no-throw-in-detour-target.js.map +0 -1
- package/dist/rules/no-throw-in-implementation.d.ts +0 -9
- package/dist/rules/no-throw-in-implementation.d.ts.map +0 -1
- package/dist/rules/no-throw-in-implementation.js +0 -34
- package/dist/rules/no-throw-in-implementation.js.map +0 -1
- package/dist/rules/prefer-schema-inference.d.ts +0 -7
- package/dist/rules/prefer-schema-inference.d.ts.map +0 -1
- package/dist/rules/prefer-schema-inference.js +0 -86
- package/dist/rules/prefer-schema-inference.js.map +0 -1
- package/dist/rules/scan.d.ts +0 -8
- package/dist/rules/scan.d.ts.map +0 -1
- package/dist/rules/scan.js +0 -32
- package/dist/rules/scan.js.map +0 -1
- package/dist/rules/specs.d.ts +0 -29
- package/dist/rules/specs.d.ts.map +0 -1
- package/dist/rules/specs.js +0 -192
- package/dist/rules/specs.js.map +0 -1
- package/dist/rules/structure.d.ts +0 -13
- package/dist/rules/structure.d.ts.map +0 -1
- package/dist/rules/structure.js +0 -142
- package/dist/rules/structure.js.map +0 -1
- package/dist/rules/types.d.ts +0 -52
- package/dist/rules/types.d.ts.map +0 -1
- package/dist/rules/types.js +0 -2
- package/dist/rules/types.js.map +0 -1
- package/dist/rules/valid-describe-refs.d.ts +0 -7
- package/dist/rules/valid-describe-refs.d.ts.map +0 -1
- package/dist/rules/valid-describe-refs.js +0 -51
- package/dist/rules/valid-describe-refs.js.map +0 -1
- package/dist/rules/valid-detour-refs.d.ts +0 -6
- package/dist/rules/valid-detour-refs.d.ts.map +0 -1
- package/dist/rules/valid-detour-refs.js +0 -116
- package/dist/rules/valid-detour-refs.js.map +0 -1
- package/src/__tests__/cli.test.ts +0 -198
- package/src/__tests__/drift.test.ts +0 -74
- package/src/__tests__/formatters.test.ts +0 -157
- package/src/__tests__/implementation-returns-result.test.ts +0 -128
- package/src/__tests__/no-direct-implementation-call.test.ts +0 -83
- package/src/__tests__/no-sync-result-assumption.test.ts +0 -85
- package/src/__tests__/no-throw-in-detour-target.test.ts +0 -78
- package/src/__tests__/prefer-schema-inference.test.ts +0 -84
- package/src/__tests__/rules.test.ts +0 -215
- package/src/__tests__/valid-describe-refs.test.ts +0 -60
- package/src/rules/no-direct-impl-in-route.ts +0 -77
- package/src/rules/no-throw-in-detour-target.ts +0 -150
- package/src/rules/valid-detour-refs.ts +0 -187
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { collectTrailIds } from './specs.js';
|
|
2
|
-
const trackBraces = (line, state) => {
|
|
3
|
-
for (const ch of line) {
|
|
4
|
-
if (ch === '{') {
|
|
5
|
-
state.depth += 1;
|
|
6
|
-
state.found = true;
|
|
7
|
-
}
|
|
8
|
-
if (ch === '}') {
|
|
9
|
-
state.depth -= 1;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const collectArrayText = (lines, start) => {
|
|
14
|
-
let text = '';
|
|
15
|
-
for (let k = start; k < lines.length && k < start + 20; k += 1) {
|
|
16
|
-
const line = lines[k];
|
|
17
|
-
if (!line) {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
text += `${line}\n`;
|
|
21
|
-
if (text.includes(']')) {
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return text;
|
|
26
|
-
};
|
|
27
|
-
const findMissingDetourTargets = (text, knownIds) => {
|
|
28
|
-
const missing = [];
|
|
29
|
-
for (const m of text.matchAll(/target\s*:\s*["'`]([^"'`]+)["'`]/g)) {
|
|
30
|
-
const [, id] = m;
|
|
31
|
-
if (id && !knownIds.has(id)) {
|
|
32
|
-
missing.push(id);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return missing;
|
|
36
|
-
};
|
|
37
|
-
const findMissingPlainDetours = (text, knownIds) => {
|
|
38
|
-
const missing = [];
|
|
39
|
-
const cleaned = text.replaceAll(/target\s*:\s*["'`][^"'`]+["'`]/g, '');
|
|
40
|
-
for (const m of cleaned.matchAll(/["'`]([^"'`]+)["'`]/g)) {
|
|
41
|
-
const [, id] = m;
|
|
42
|
-
if (id && id.includes('.') && !knownIds.has(id)) {
|
|
43
|
-
missing.push(id);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return missing;
|
|
47
|
-
};
|
|
48
|
-
const findAllMissingDetours = (text, knownIds) => [
|
|
49
|
-
...findMissingDetourTargets(text, knownIds),
|
|
50
|
-
...findMissingPlainDetours(text, knownIds),
|
|
51
|
-
];
|
|
52
|
-
const addMissingDetourDiagnostics = (specLine, j, lines, trailId, lineNum, filePath, knownIds, diagnostics) => {
|
|
53
|
-
if (!/\bdetours\s*:/.test(specLine)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
for (const targetId of findAllMissingDetours(collectArrayText(lines, j), knownIds)) {
|
|
57
|
-
diagnostics.push({
|
|
58
|
-
filePath,
|
|
59
|
-
line: lineNum,
|
|
60
|
-
message: `Trail "${trailId}" has detour targeting "${targetId}" which is not defined.`,
|
|
61
|
-
rule: 'valid-detour-refs',
|
|
62
|
-
severity: 'error',
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const scanTrailDetours = (lines, startIndex, trailId, filePath, knownIds, diagnostics) => {
|
|
67
|
-
const braceState = { depth: 0, found: false };
|
|
68
|
-
for (let j = startIndex; j < lines.length && j < startIndex + 200; j += 1) {
|
|
69
|
-
const specLine = lines[j];
|
|
70
|
-
if (!specLine) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
trackBraces(specLine, braceState);
|
|
74
|
-
addMissingDetourDiagnostics(specLine, j, lines, trailId, startIndex + 1, filePath, knownIds, diagnostics);
|
|
75
|
-
if (braceState.found && braceState.depth <= 0) {
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const processLine = (line, i, lines, filePath, knownIds, diagnostics) => {
|
|
81
|
-
const trailMatch = line.match(/\b(?:trail|hike)\s*\(\s*["'`]([^"'`]+)["'`]/);
|
|
82
|
-
if (!trailMatch) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const [, trailId] = trailMatch;
|
|
86
|
-
if (!trailId) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
scanTrailDetours(lines, i, trailId, filePath, knownIds, diagnostics);
|
|
90
|
-
};
|
|
91
|
-
const checkDetourRefs = (sourceCode, filePath, knownIds) => {
|
|
92
|
-
const diagnostics = [];
|
|
93
|
-
const lines = sourceCode.split('\n');
|
|
94
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
95
|
-
const line = lines[i];
|
|
96
|
-
if (line) {
|
|
97
|
-
processLine(line, i, lines, filePath, knownIds, diagnostics);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return diagnostics;
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Checks that all trail IDs referenced in `detours` declarations exist.
|
|
104
|
-
*/
|
|
105
|
-
export const validDetourRefs = {
|
|
106
|
-
check(sourceCode, filePath) {
|
|
107
|
-
return checkDetourRefs(sourceCode, filePath, collectTrailIds(sourceCode));
|
|
108
|
-
},
|
|
109
|
-
checkWithContext(sourceCode, filePath, context) {
|
|
110
|
-
return checkDetourRefs(sourceCode, filePath, context.knownTrailIds);
|
|
111
|
-
},
|
|
112
|
-
description: 'Ensure all detour target trail IDs reference defined trails.',
|
|
113
|
-
name: 'valid-detour-refs',
|
|
114
|
-
severity: 'error',
|
|
115
|
-
};
|
|
116
|
-
//# sourceMappingURL=valid-detour-refs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"valid-detour-refs.js","sourceRoot":"","sources":["../../src/rules/valid-detour-refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAY7C,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,KAAiB,EAAQ,EAAE;IAC5D,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;QACtB,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACf,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;YACjB,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;QACrB,CAAC;QACD,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACf,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,KAAwB,EAAE,KAAa,EAAU,EAAE;IAC3E,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,KAAK,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,SAAS;QACX,CAAC;QACD,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC;QACpB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM;QACR,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAC/B,IAAY,EACZ,QAA6B,EACnB,EAAE;IACZ,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,CA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AC;IACtE,CAAC;IACD,WAAW,EAAE,8DAA8D;IAC3E,IAAI,EAAE,mBAAmB;IACzB,QAAQ,EAAE,OAAO;CAClB,CAAC"}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
|
|
6
|
-
import { formatWardenReport, runWarden } from '../cli.js';
|
|
7
|
-
|
|
8
|
-
const makeTempDir = (): string => {
|
|
9
|
-
const dir = join(
|
|
10
|
-
tmpdir(),
|
|
11
|
-
`warden-test-${Date.now()}-${Math.random().toString(36).slice(2)}`
|
|
12
|
-
);
|
|
13
|
-
mkdirSync(dir, { recursive: true });
|
|
14
|
-
return dir;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
describe('runWarden', () => {
|
|
18
|
-
test('produces a report with diagnostics for bad code', async () => {
|
|
19
|
-
const dir = makeTempDir();
|
|
20
|
-
try {
|
|
21
|
-
writeFileSync(
|
|
22
|
-
join(dir, 'bad.ts'),
|
|
23
|
-
`trail("entity.show", {
|
|
24
|
-
implementation: async (input, ctx) => {
|
|
25
|
-
throw new Error("boom");
|
|
26
|
-
}
|
|
27
|
-
})`
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const report = await runWarden({ rootDir: dir });
|
|
31
|
-
expect(report.errorCount).toBeGreaterThan(0);
|
|
32
|
-
expect(report.passed).toBe(false);
|
|
33
|
-
} finally {
|
|
34
|
-
rmSync(dir, { force: true, recursive: true });
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('passes for clean code', async () => {
|
|
39
|
-
const dir = makeTempDir();
|
|
40
|
-
try {
|
|
41
|
-
writeFileSync(
|
|
42
|
-
join(dir, 'good.ts'),
|
|
43
|
-
`trail("entity.show", {
|
|
44
|
-
implementation: async (input, ctx) => {
|
|
45
|
-
return Result.ok(data);
|
|
46
|
-
}
|
|
47
|
-
})`
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const report = await runWarden({ rootDir: dir });
|
|
51
|
-
expect(report.errorCount).toBe(0);
|
|
52
|
-
expect(report.passed).toBe(true);
|
|
53
|
-
} finally {
|
|
54
|
-
rmSync(dir, { force: true, recursive: true });
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('lintOnly skips drift check', async () => {
|
|
59
|
-
const dir = makeTempDir();
|
|
60
|
-
try {
|
|
61
|
-
writeFileSync(join(dir, 'empty.ts'), 'export {}');
|
|
62
|
-
const report = await runWarden({ lintOnly: true, rootDir: dir });
|
|
63
|
-
expect(report.drift).toBeNull();
|
|
64
|
-
} finally {
|
|
65
|
-
rmSync(dir, { force: true, recursive: true });
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('driftOnly skips lint', async () => {
|
|
70
|
-
const dir = makeTempDir();
|
|
71
|
-
try {
|
|
72
|
-
// Even with bad code, driftOnly should produce 0 diagnostics
|
|
73
|
-
writeFileSync(
|
|
74
|
-
join(dir, 'bad.ts'),
|
|
75
|
-
`trail("x", { implementation: async () => { throw new Error("x"); } })`
|
|
76
|
-
);
|
|
77
|
-
const report = await runWarden({ driftOnly: true, rootDir: dir });
|
|
78
|
-
expect(report.diagnostics.length).toBe(0);
|
|
79
|
-
expect(report.drift).not.toBeNull();
|
|
80
|
-
} finally {
|
|
81
|
-
rmSync(dir, { force: true, recursive: true });
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('uses project context for detour references across files', async () => {
|
|
86
|
-
const dir = makeTempDir();
|
|
87
|
-
try {
|
|
88
|
-
writeFileSync(
|
|
89
|
-
join(dir, 'show.ts'),
|
|
90
|
-
`trail("entity.show", {
|
|
91
|
-
detours: { NotFoundError: ["entity.search"] },
|
|
92
|
-
implementation: async (input, ctx) => {
|
|
93
|
-
return Result.ok(data);
|
|
94
|
-
}
|
|
95
|
-
})`
|
|
96
|
-
);
|
|
97
|
-
writeFileSync(
|
|
98
|
-
join(dir, 'search.ts'),
|
|
99
|
-
`trail("entity.search", {
|
|
100
|
-
implementation: async (input, ctx) => {
|
|
101
|
-
return Result.ok(data);
|
|
102
|
-
}
|
|
103
|
-
})`
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const report = await runWarden({ rootDir: dir });
|
|
107
|
-
const detourRefErrors = report.diagnostics.filter(
|
|
108
|
-
(diagnostic) => diagnostic.rule === 'valid-detour-refs'
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
expect(detourRefErrors).toHaveLength(0);
|
|
112
|
-
} finally {
|
|
113
|
-
rmSync(dir, { force: true, recursive: true });
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('flags throws in detour targets declared in another file', async () => {
|
|
118
|
-
const dir = makeTempDir();
|
|
119
|
-
try {
|
|
120
|
-
writeFileSync(
|
|
121
|
-
join(dir, 'show.ts'),
|
|
122
|
-
`trail("entity.show", {
|
|
123
|
-
detours: { NotFoundError: ["entity.search"] },
|
|
124
|
-
implementation: async (input, ctx) => {
|
|
125
|
-
return Result.ok(data);
|
|
126
|
-
}
|
|
127
|
-
})`
|
|
128
|
-
);
|
|
129
|
-
writeFileSync(
|
|
130
|
-
join(dir, 'search.ts'),
|
|
131
|
-
`trail("entity.search", {
|
|
132
|
-
implementation: async (input, ctx) => {
|
|
133
|
-
throw new Error("boom");
|
|
134
|
-
}
|
|
135
|
-
})`
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
const report = await runWarden({ rootDir: dir });
|
|
139
|
-
const detourThrowRules = report.diagnostics.filter(
|
|
140
|
-
(diagnostic) => diagnostic.rule === 'no-throw-in-detour-target'
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
expect(detourThrowRules).toHaveLength(1);
|
|
144
|
-
expect(detourThrowRules[0]?.message).toContain('entity.search');
|
|
145
|
-
} finally {
|
|
146
|
-
rmSync(dir, { force: true, recursive: true });
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('formatWardenReport', () => {
|
|
152
|
-
test('formats a clean report', () => {
|
|
153
|
-
const output = formatWardenReport({
|
|
154
|
-
diagnostics: [],
|
|
155
|
-
drift: { committedHash: null, currentHash: 'stub', stale: false },
|
|
156
|
-
errorCount: 0,
|
|
157
|
-
passed: true,
|
|
158
|
-
warnCount: 0,
|
|
159
|
-
});
|
|
160
|
-
expect(output).toContain('Warden Report');
|
|
161
|
-
expect(output).toContain('Lint: clean');
|
|
162
|
-
expect(output).toContain('Drift: clean');
|
|
163
|
-
expect(output).toContain('Result: PASS');
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test('formats a report with errors', () => {
|
|
167
|
-
const output = formatWardenReport({
|
|
168
|
-
diagnostics: [
|
|
169
|
-
{
|
|
170
|
-
filePath: 'src/trails/entity.ts',
|
|
171
|
-
line: 3,
|
|
172
|
-
message: 'Do not throw inside implementation.',
|
|
173
|
-
rule: 'no-throw-in-implementation',
|
|
174
|
-
severity: 'error',
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
drift: { committedHash: null, currentHash: 'stub', stale: false },
|
|
178
|
-
errorCount: 1,
|
|
179
|
-
passed: false,
|
|
180
|
-
warnCount: 0,
|
|
181
|
-
});
|
|
182
|
-
expect(output).toContain('1 errors');
|
|
183
|
-
expect(output).toContain('Result: FAIL');
|
|
184
|
-
expect(output).toContain('entity.ts:3');
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
test('formats a report with stale drift', () => {
|
|
188
|
-
const output = formatWardenReport({
|
|
189
|
-
diagnostics: [],
|
|
190
|
-
drift: { committedHash: 'abc', currentHash: 'def', stale: true },
|
|
191
|
-
errorCount: 0,
|
|
192
|
-
passed: false,
|
|
193
|
-
warnCount: 0,
|
|
194
|
-
});
|
|
195
|
-
expect(output).toContain('surface.lock is stale');
|
|
196
|
-
expect(output).toContain('Result: FAIL');
|
|
197
|
-
});
|
|
198
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
|
|
6
|
-
import { trail, topo, Result } from '@ontrails/core';
|
|
7
|
-
import { hashSurfaceMap, generateSurfaceMap } from '@ontrails/schema';
|
|
8
|
-
import { z } from 'zod';
|
|
9
|
-
|
|
10
|
-
import { checkDrift } from '../drift.js';
|
|
11
|
-
|
|
12
|
-
const makeTopo = () => {
|
|
13
|
-
const t = trail('test.hello', {
|
|
14
|
-
implementation: () => Result.ok({ greeting: 'hi' }),
|
|
15
|
-
input: z.object({ name: z.string() }),
|
|
16
|
-
output: z.object({ greeting: z.string() }),
|
|
17
|
-
});
|
|
18
|
-
return topo('test-app', { t });
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const createTempDir = (): string => {
|
|
22
|
-
const dir = join(tmpdir(), `drift-test-${Date.now()}`);
|
|
23
|
-
mkdirSync(dir, { recursive: true });
|
|
24
|
-
return dir;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
describe('checkDrift', () => {
|
|
28
|
-
test('returns stale: false when no topo is provided', async () => {
|
|
29
|
-
const result = await checkDrift('/tmp');
|
|
30
|
-
expect(result.stale).toBe(false);
|
|
31
|
-
expect(result.currentHash).toBe('unknown');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('returns stale: false when no lock file exists', async () => {
|
|
35
|
-
const dir = createTempDir();
|
|
36
|
-
try {
|
|
37
|
-
const result = await checkDrift(dir, makeTopo());
|
|
38
|
-
expect(result.stale).toBe(false);
|
|
39
|
-
expect(result.committedHash).toBeNull();
|
|
40
|
-
expect(result.currentHash.length).toBeGreaterThan(0);
|
|
41
|
-
} finally {
|
|
42
|
-
rmSync(dir, { force: true, recursive: true });
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('returns stale: false when lock matches current hash', async () => {
|
|
47
|
-
const dir = createTempDir();
|
|
48
|
-
try {
|
|
49
|
-
const tp = makeTopo();
|
|
50
|
-
const hash = hashSurfaceMap(generateSurfaceMap(tp));
|
|
51
|
-
writeFileSync(join(dir, 'surface.lock'), `${hash}\n`);
|
|
52
|
-
|
|
53
|
-
const result = await checkDrift(dir, tp);
|
|
54
|
-
expect(result.stale).toBe(false);
|
|
55
|
-
expect(result.committedHash).toBe(hash);
|
|
56
|
-
expect(result.currentHash).toBe(hash);
|
|
57
|
-
} finally {
|
|
58
|
-
rmSync(dir, { force: true, recursive: true });
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('returns stale: true when lock does not match', async () => {
|
|
63
|
-
const dir = createTempDir();
|
|
64
|
-
try {
|
|
65
|
-
writeFileSync(join(dir, 'surface.lock'), 'outdated-hash\n');
|
|
66
|
-
|
|
67
|
-
const result = await checkDrift(dir, makeTopo());
|
|
68
|
-
expect(result.stale).toBe(true);
|
|
69
|
-
expect(result.committedHash).toBe('outdated-hash');
|
|
70
|
-
} finally {
|
|
71
|
-
rmSync(dir, { force: true, recursive: true });
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import type { WardenReport } from '../cli.js';
|
|
4
|
-
import {
|
|
5
|
-
formatGitHubAnnotations,
|
|
6
|
-
formatJson,
|
|
7
|
-
formatSummary,
|
|
8
|
-
} from '../formatters.js';
|
|
9
|
-
|
|
10
|
-
const cleanReport: WardenReport = {
|
|
11
|
-
diagnostics: [],
|
|
12
|
-
drift: { committedHash: 'abc', currentHash: 'abc', stale: false },
|
|
13
|
-
errorCount: 0,
|
|
14
|
-
passed: true,
|
|
15
|
-
warnCount: 0,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const reportWithDiagnostics: WardenReport = {
|
|
19
|
-
diagnostics: [
|
|
20
|
-
{
|
|
21
|
-
filePath: 'packages/core/src/result.ts',
|
|
22
|
-
line: 42,
|
|
23
|
-
message: 'Throw statement found in trail implementation',
|
|
24
|
-
rule: 'no-throw-in-implementation',
|
|
25
|
-
severity: 'error',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
filePath: 'packages/core/src/trails.ts',
|
|
29
|
-
line: 15,
|
|
30
|
-
message: 'Trail "entity.show" has no output schema',
|
|
31
|
-
rule: 'require-output-schema',
|
|
32
|
-
severity: 'warn',
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
drift: null,
|
|
36
|
-
errorCount: 1,
|
|
37
|
-
passed: false,
|
|
38
|
-
warnCount: 1,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const reportWithDrift: WardenReport = {
|
|
42
|
-
diagnostics: [],
|
|
43
|
-
drift: { committedHash: 'abc', currentHash: 'def', stale: true },
|
|
44
|
-
errorCount: 0,
|
|
45
|
-
passed: false,
|
|
46
|
-
warnCount: 0,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
describe('formatGitHubAnnotations', () => {
|
|
50
|
-
test('produces empty string for clean report', () => {
|
|
51
|
-
expect(formatGitHubAnnotations(cleanReport)).toBe('');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('maps error severity to ::error', () => {
|
|
55
|
-
const output = formatGitHubAnnotations(reportWithDiagnostics);
|
|
56
|
-
expect(output).toContain(
|
|
57
|
-
'::error file=packages/core/src/result.ts,line=42::no-throw-in-implementation:'
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('maps warn severity to ::warning', () => {
|
|
62
|
-
const output = formatGitHubAnnotations(reportWithDiagnostics);
|
|
63
|
-
expect(output).toContain(
|
|
64
|
-
'::warning file=packages/core/src/trails.ts,line=15::require-output-schema:'
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('emits drift as a single ::error annotation', () => {
|
|
69
|
-
const output = formatGitHubAnnotations(reportWithDrift);
|
|
70
|
-
expect(output).toContain('::error::drift: surface.lock is stale');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('produces one line per diagnostic', () => {
|
|
74
|
-
const lines = formatGitHubAnnotations(reportWithDiagnostics)
|
|
75
|
-
.split('\n')
|
|
76
|
-
.filter(Boolean);
|
|
77
|
-
expect(lines).toHaveLength(2);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('formatJson', () => {
|
|
82
|
-
test('produces valid JSON', () => {
|
|
83
|
-
const parsed = JSON.parse(formatJson(cleanReport));
|
|
84
|
-
expect(parsed).toBeDefined();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('includes passed status', () => {
|
|
88
|
-
const parsed = JSON.parse(formatJson(cleanReport));
|
|
89
|
-
expect(parsed.passed).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('includes summary counts', () => {
|
|
93
|
-
const parsed = JSON.parse(formatJson(reportWithDiagnostics));
|
|
94
|
-
expect(parsed.summary).toEqual({
|
|
95
|
-
errors: 1,
|
|
96
|
-
suggestions: 0,
|
|
97
|
-
warnings: 1,
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('includes diagnostics array', () => {
|
|
102
|
-
const parsed = JSON.parse(formatJson(reportWithDiagnostics));
|
|
103
|
-
expect(parsed.diagnostics).toHaveLength(2);
|
|
104
|
-
expect(parsed.diagnostics[0].rule).toBe('no-throw-in-implementation');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('includes null drift when absent', () => {
|
|
108
|
-
const parsed = JSON.parse(formatJson(reportWithDiagnostics));
|
|
109
|
-
expect(parsed.drift).toBeNull();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('includes drift result when present', () => {
|
|
113
|
-
const parsed = JSON.parse(formatJson(reportWithDrift));
|
|
114
|
-
expect(parsed.drift.stale).toBe(true);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('formatSummary', () => {
|
|
119
|
-
test('includes markdown heading', () => {
|
|
120
|
-
expect(formatSummary(cleanReport)).toContain('## Warden Report');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('shows PASS for clean report', () => {
|
|
124
|
-
expect(formatSummary(cleanReport)).toContain('**Result: PASS**');
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('shows FAIL for failing report', () => {
|
|
128
|
-
expect(formatSummary(reportWithDiagnostics)).toContain('**Result: FAIL**');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('groups errors under ### Errors heading', () => {
|
|
132
|
-
const output = formatSummary(reportWithDiagnostics);
|
|
133
|
-
expect(output).toContain('### Errors');
|
|
134
|
-
expect(output).toContain('no-throw-in-implementation');
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test('groups warnings under ### Warnings heading', () => {
|
|
138
|
-
const output = formatSummary(reportWithDiagnostics);
|
|
139
|
-
expect(output).toContain('### Warnings');
|
|
140
|
-
expect(output).toContain('require-output-schema');
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
test('includes file:line in backticks', () => {
|
|
144
|
-
const output = formatSummary(reportWithDiagnostics);
|
|
145
|
-
expect(output).toContain('`packages/core/src/result.ts:42`');
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test('includes drift section when stale', () => {
|
|
149
|
-
const output = formatSummary(reportWithDrift);
|
|
150
|
-
expect(output).toContain('### Drift');
|
|
151
|
-
expect(output).toContain('surface.lock is stale');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test('omits drift section when clean', () => {
|
|
155
|
-
expect(formatSummary(cleanReport)).not.toContain('### Drift');
|
|
156
|
-
});
|
|
157
|
-
});
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import { implementationReturnsResult } from '../rules/implementation-returns-result.js';
|
|
4
|
-
|
|
5
|
-
const TEST_FILE = 'test.ts';
|
|
6
|
-
|
|
7
|
-
describe('implementation-returns-result', () => {
|
|
8
|
-
test('flags raw object return in trail implementation', () => {
|
|
9
|
-
const code = `
|
|
10
|
-
trail("entity.show", {
|
|
11
|
-
implementation: async (input, ctx) => {
|
|
12
|
-
return { name: "foo" };
|
|
13
|
-
}
|
|
14
|
-
})`;
|
|
15
|
-
|
|
16
|
-
const diagnostics = implementationReturnsResult.check(code, TEST_FILE);
|
|
17
|
-
|
|
18
|
-
expect(diagnostics.length).toBe(1);
|
|
19
|
-
expect(diagnostics[0]?.rule).toBe('implementation-returns-result');
|
|
20
|
-
expect(diagnostics[0]?.severity).toBe('error');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('allows Result.ok() and returning ctx.follow() results', () => {
|
|
24
|
-
const code = `
|
|
25
|
-
hike("entity.onboard", {
|
|
26
|
-
implementation: async (input, ctx) => {
|
|
27
|
-
const result = await ctx.follow("entity.create", input);
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
trail("entity.create", {
|
|
33
|
-
implementation: async (input, ctx) => Result.ok({ id: "123" })
|
|
34
|
-
})`;
|
|
35
|
-
|
|
36
|
-
const diagnostics = implementationReturnsResult.check(code, TEST_FILE);
|
|
37
|
-
|
|
38
|
-
expect(diagnostics.length).toBe(0);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('flags concise raw implementation bodies', () => {
|
|
42
|
-
const code = `
|
|
43
|
-
trail("entity.create", {
|
|
44
|
-
implementation: async (input, ctx) => ({ id: "123" })
|
|
45
|
-
})`;
|
|
46
|
-
|
|
47
|
-
const diagnostics = implementationReturnsResult.check(code, TEST_FILE);
|
|
48
|
-
|
|
49
|
-
expect(diagnostics.length).toBe(1);
|
|
50
|
-
expect(diagnostics[0]?.message).toContain('entity.create');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('ignores return statements inside nested callbacks like .map()', () => {
|
|
54
|
-
const code = `
|
|
55
|
-
trail("entity.list", {
|
|
56
|
-
implementation: async (input, ctx) => {
|
|
57
|
-
const items = ["a", "b", "c"];
|
|
58
|
-
const mapped = items.map((item) => {
|
|
59
|
-
return { name: item };
|
|
60
|
-
});
|
|
61
|
-
const filtered = items.filter((item) => {
|
|
62
|
-
return item !== "b";
|
|
63
|
-
});
|
|
64
|
-
return Result.ok(mapped);
|
|
65
|
-
}
|
|
66
|
-
})`;
|
|
67
|
-
|
|
68
|
-
const diagnostics = implementationReturnsResult.check(code, TEST_FILE);
|
|
69
|
-
|
|
70
|
-
expect(diagnostics.length).toBe(0);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('ignores return statements inside .then() callbacks', () => {
|
|
74
|
-
const code = `
|
|
75
|
-
trail("entity.fetch", {
|
|
76
|
-
implementation: async (input, ctx) => {
|
|
77
|
-
const data = await somePromise.then((res) => {
|
|
78
|
-
return res.json();
|
|
79
|
-
});
|
|
80
|
-
return Result.ok(data);
|
|
81
|
-
}
|
|
82
|
-
})`;
|
|
83
|
-
|
|
84
|
-
const diagnostics = implementationReturnsResult.check(code, TEST_FILE);
|
|
85
|
-
|
|
86
|
-
expect(diagnostics.length).toBe(0);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('still flags raw returns at the implementation level', () => {
|
|
90
|
-
const code = `
|
|
91
|
-
trail("entity.list", {
|
|
92
|
-
implementation: async (input, ctx) => {
|
|
93
|
-
const items = ["a", "b"].map((item) => {
|
|
94
|
-
return { name: item };
|
|
95
|
-
});
|
|
96
|
-
return items;
|
|
97
|
-
}
|
|
98
|
-
})`;
|
|
99
|
-
|
|
100
|
-
const diagnostics = implementationReturnsResult.check(code, TEST_FILE);
|
|
101
|
-
|
|
102
|
-
expect(diagnostics.length).toBe(1);
|
|
103
|
-
expect(diagnostics[0]?.message).toContain('entity.list');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('allows returning explicitly Result-typed local helpers', () => {
|
|
107
|
-
const code = `
|
|
108
|
-
const buildDetail = (trailId: string): Result<object, Error> =>
|
|
109
|
-
Result.ok({ trailId });
|
|
110
|
-
|
|
111
|
-
const buildDiff = async (): Promise<Result<object, Error>> =>
|
|
112
|
-
Result.ok({ breaking: [] });
|
|
113
|
-
|
|
114
|
-
trail("survey", {
|
|
115
|
-
implementation: async (input, ctx) => {
|
|
116
|
-
if (input.diff) {
|
|
117
|
-
return await buildDiff();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return buildDetail(input.trailId);
|
|
121
|
-
}
|
|
122
|
-
})`;
|
|
123
|
-
|
|
124
|
-
const diagnostics = implementationReturnsResult.check(code, TEST_FILE);
|
|
125
|
-
|
|
126
|
-
expect(diagnostics.length).toBe(0);
|
|
127
|
-
});
|
|
128
|
-
});
|