@ontrails/trails 1.0.0-beta.15 → 1.0.0-beta.16
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 +197 -2
- package/README.md +27 -0
- package/package.json +19 -8
- package/src/app.ts +15 -5
- package/src/cli.ts +303 -10
- package/src/completions.ts +240 -0
- package/src/load-app-mirror.ts +160 -0
- package/src/local-state-io.ts +153 -0
- package/src/project-writes.ts +320 -0
- package/src/run-collision.ts +125 -0
- package/src/run-completions-install.ts +179 -0
- package/src/run-example.ts +149 -0
- package/src/run-examples.ts +148 -0
- package/src/run-quiet.ts +75 -0
- package/src/run-trace.ts +273 -0
- package/src/run-warden.ts +39 -0
- package/src/run-watch.ts +432 -0
- package/src/scaffold-versions.generated.ts +12 -0
- package/src/trails/add-surface.ts +45 -23
- package/src/trails/add-trail.ts +27 -17
- package/src/trails/add-verify.ts +57 -17
- package/src/trails/completions-complete.ts +165 -0
- package/src/trails/completions.ts +47 -0
- package/src/trails/create-scaffold.ts +86 -33
- package/src/trails/create.ts +11 -3
- package/src/trails/dev-clean.ts +6 -1
- package/src/trails/dev-reset.ts +6 -1
- package/src/trails/dev-stats.ts +6 -1
- package/src/trails/dev-support.ts +29 -17
- package/src/trails/draft-promote.ts +289 -80
- package/src/trails/guide.ts +54 -34
- package/src/trails/load-app.ts +251 -56
- package/src/trails/root-dir.ts +21 -0
- package/src/trails/run-example.ts +482 -0
- package/src/trails/run-examples.ts +141 -0
- package/src/trails/run.ts +403 -0
- package/src/trails/survey.ts +506 -200
- package/src/trails/topo-activation.ts +385 -0
- package/src/trails/topo-compile.ts +55 -0
- package/src/trails/topo-history.ts +6 -1
- package/src/trails/topo-output-schemas.ts +175 -0
- package/src/trails/topo-pin.ts +19 -6
- package/src/trails/topo-read-support.ts +171 -228
- package/src/trails/topo-reports.ts +400 -25
- package/src/trails/topo-store-support.ts +43 -19
- package/src/trails/topo-support.ts +18 -28
- package/src/trails/topo-unpin.ts +6 -1
- package/src/trails/topo-verify.ts +18 -5
- package/src/trails/topo.ts +60 -23
- package/src/trails/warden-guide.ts +121 -0
- package/src/trails/warden.ts +137 -56
- package/src/versions.ts +3 -18
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/__tests__/examples.test.ts +0 -45
- package/dist/bin/trails.d.ts +0 -3
- package/dist/bin/trails.d.ts.map +0 -1
- package/dist/bin/trails.js +0 -4
- package/dist/bin/trails.js.map +0 -1
- package/dist/src/app.d.ts +0 -2
- package/dist/src/app.d.ts.map +0 -1
- package/dist/src/app.js +0 -22
- package/dist/src/app.js.map +0 -1
- package/dist/src/clack.d.ts +0 -9
- package/dist/src/clack.d.ts.map +0 -1
- package/dist/src/clack.js +0 -84
- package/dist/src/clack.js.map +0 -1
- package/dist/src/cli.d.ts +0 -2
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -14
- package/dist/src/cli.js.map +0 -1
- package/dist/src/trails/add-surface.d.ts +0 -13
- package/dist/src/trails/add-surface.d.ts.map +0 -1
- package/dist/src/trails/add-surface.js +0 -110
- package/dist/src/trails/add-surface.js.map +0 -1
- package/dist/src/trails/add-trail.d.ts +0 -12
- package/dist/src/trails/add-trail.d.ts.map +0 -1
- package/dist/src/trails/add-trail.js +0 -104
- package/dist/src/trails/add-trail.js.map +0 -1
- package/dist/src/trails/add-trailhead.d.ts +0 -13
- package/dist/src/trails/add-trailhead.d.ts.map +0 -1
- package/dist/src/trails/add-trailhead.js +0 -88
- package/dist/src/trails/add-trailhead.js.map +0 -1
- package/dist/src/trails/add-verify.d.ts +0 -10
- package/dist/src/trails/add-verify.d.ts.map +0 -1
- package/dist/src/trails/add-verify.js +0 -68
- package/dist/src/trails/add-verify.js.map +0 -1
- package/dist/src/trails/create-scaffold.d.ts +0 -15
- package/dist/src/trails/create-scaffold.d.ts.map +0 -1
- package/dist/src/trails/create-scaffold.js +0 -295
- package/dist/src/trails/create-scaffold.js.map +0 -1
- package/dist/src/trails/create.d.ts +0 -18
- package/dist/src/trails/create.d.ts.map +0 -1
- package/dist/src/trails/create.js +0 -126
- package/dist/src/trails/create.js.map +0 -1
- package/dist/src/trails/dev-clean.d.ts +0 -9
- package/dist/src/trails/dev-clean.d.ts.map +0 -1
- package/dist/src/trails/dev-clean.js +0 -66
- package/dist/src/trails/dev-clean.js.map +0 -1
- package/dist/src/trails/dev-reset.d.ts +0 -6
- package/dist/src/trails/dev-reset.d.ts.map +0 -1
- package/dist/src/trails/dev-reset.js +0 -39
- package/dist/src/trails/dev-reset.js.map +0 -1
- package/dist/src/trails/dev-stats.d.ts +0 -7
- package/dist/src/trails/dev-stats.d.ts.map +0 -1
- package/dist/src/trails/dev-stats.js +0 -61
- package/dist/src/trails/dev-stats.js.map +0 -1
- package/dist/src/trails/dev-support.d.ts +0 -64
- package/dist/src/trails/dev-support.d.ts.map +0 -1
- package/dist/src/trails/dev-support.js +0 -181
- package/dist/src/trails/dev-support.js.map +0 -1
- package/dist/src/trails/draft-promote.d.ts +0 -18
- package/dist/src/trails/draft-promote.d.ts.map +0 -1
- package/dist/src/trails/draft-promote.js +0 -400
- package/dist/src/trails/draft-promote.js.map +0 -1
- package/dist/src/trails/guide.d.ts +0 -21
- package/dist/src/trails/guide.d.ts.map +0 -1
- package/dist/src/trails/guide.js +0 -61
- package/dist/src/trails/guide.js.map +0 -1
- package/dist/src/trails/load-app.d.ts +0 -12
- package/dist/src/trails/load-app.d.ts.map +0 -1
- package/dist/src/trails/load-app.js +0 -415
- package/dist/src/trails/load-app.js.map +0 -1
- package/dist/src/trails/project.d.ts +0 -8
- package/dist/src/trails/project.d.ts.map +0 -1
- package/dist/src/trails/project.js +0 -54
- package/dist/src/trails/project.js.map +0 -1
- package/dist/src/trails/survey.d.ts +0 -18
- package/dist/src/trails/survey.d.ts.map +0 -1
- package/dist/src/trails/survey.js +0 -234
- package/dist/src/trails/survey.js.map +0 -1
- package/dist/src/trails/topo-constants.d.ts +0 -3
- package/dist/src/trails/topo-constants.d.ts.map +0 -1
- package/dist/src/trails/topo-constants.js +0 -3
- package/dist/src/trails/topo-constants.js.map +0 -1
- package/dist/src/trails/topo-export.d.ts +0 -19
- package/dist/src/trails/topo-export.d.ts.map +0 -1
- package/dist/src/trails/topo-export.js +0 -31
- package/dist/src/trails/topo-export.js.map +0 -1
- package/dist/src/trails/topo-history.d.ts +0 -20
- package/dist/src/trails/topo-history.d.ts.map +0 -1
- package/dist/src/trails/topo-history.js +0 -32
- package/dist/src/trails/topo-history.js.map +0 -1
- package/dist/src/trails/topo-pin.d.ts +0 -17
- package/dist/src/trails/topo-pin.d.ts.map +0 -1
- package/dist/src/trails/topo-pin.js +0 -31
- package/dist/src/trails/topo-pin.js.map +0 -1
- package/dist/src/trails/topo-read-support.d.ts +0 -58
- package/dist/src/trails/topo-read-support.d.ts.map +0 -1
- package/dist/src/trails/topo-read-support.js +0 -167
- package/dist/src/trails/topo-read-support.js.map +0 -1
- package/dist/src/trails/topo-reports.d.ts +0 -54
- package/dist/src/trails/topo-reports.d.ts.map +0 -1
- package/dist/src/trails/topo-reports.js +0 -128
- package/dist/src/trails/topo-reports.js.map +0 -1
- package/dist/src/trails/topo-show.d.ts +0 -23
- package/dist/src/trails/topo-show.d.ts.map +0 -1
- package/dist/src/trails/topo-show.js +0 -49
- package/dist/src/trails/topo-show.js.map +0 -1
- package/dist/src/trails/topo-store-support.d.ts +0 -13
- package/dist/src/trails/topo-store-support.d.ts.map +0 -1
- package/dist/src/trails/topo-store-support.js +0 -55
- package/dist/src/trails/topo-store-support.js.map +0 -1
- package/dist/src/trails/topo-support.d.ts +0 -76
- package/dist/src/trails/topo-support.d.ts.map +0 -1
- package/dist/src/trails/topo-support.js +0 -132
- package/dist/src/trails/topo-support.js.map +0 -1
- package/dist/src/trails/topo-unpin.d.ts +0 -20
- package/dist/src/trails/topo-unpin.d.ts.map +0 -1
- package/dist/src/trails/topo-unpin.js +0 -44
- package/dist/src/trails/topo-unpin.js.map +0 -1
- package/dist/src/trails/topo-verify.d.ts +0 -5
- package/dist/src/trails/topo-verify.d.ts.map +0 -1
- package/dist/src/trails/topo-verify.js +0 -24
- package/dist/src/trails/topo-verify.js.map +0 -1
- package/dist/src/trails/topo.d.ts +0 -5
- package/dist/src/trails/topo.d.ts.map +0 -1
- package/dist/src/trails/topo.js +0 -63
- package/dist/src/trails/topo.js.map +0 -1
- package/dist/src/trails/warden.d.ts +0 -20
- package/dist/src/trails/warden.d.ts.map +0 -1
- package/dist/src/trails/warden.js +0 -98
- package/dist/src/trails/warden.js.map +0 -1
- package/dist/src/versions.d.ts +0 -12
- package/dist/src/versions.d.ts.map +0 -1
- package/dist/src/versions.js +0 -23
- package/dist/src/versions.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/__tests__/add-trail.test.ts +0 -97
- package/src/__tests__/create.test.ts +0 -415
- package/src/__tests__/draft-promote.test.ts +0 -144
- package/src/__tests__/guide.test.ts +0 -96
- package/src/__tests__/load-app.test.ts +0 -419
- package/src/__tests__/survey.test.ts +0 -377
- package/src/__tests__/topo-dev.test.ts +0 -426
- package/src/__tests__/warden.test.ts +0 -74
- package/src/trails/topo-export.ts +0 -35
- package/src/trails/topo-show.ts +0 -54
- package/tsconfig.json +0 -9
- package/tsconfig.tests.json +0 -10
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import {
|
|
3
|
-
existsSync,
|
|
4
|
-
mkdirSync,
|
|
5
|
-
readFileSync,
|
|
6
|
-
rmSync,
|
|
7
|
-
writeFileSync,
|
|
8
|
-
} from 'node:fs';
|
|
9
|
-
import { join, resolve } from 'node:path';
|
|
10
|
-
|
|
11
|
-
import { ConflictError, Result, resource, topo, trail } from '@ontrails/core';
|
|
12
|
-
import {
|
|
13
|
-
deriveSurfaceMap,
|
|
14
|
-
deriveSurfaceMapHash,
|
|
15
|
-
deriveSurfaceMapDiff,
|
|
16
|
-
writeSurfaceMap,
|
|
17
|
-
} from '@ontrails/schema';
|
|
18
|
-
import type { SurfaceMap } from '@ontrails/schema';
|
|
19
|
-
import { z } from 'zod';
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
deriveBriefReport,
|
|
23
|
-
deriveSurveyList,
|
|
24
|
-
deriveTrailDetail,
|
|
25
|
-
surveyTrail,
|
|
26
|
-
} from '../trails/survey.js';
|
|
27
|
-
import { loadApp } from '../trails/load-app.js';
|
|
28
|
-
import type {
|
|
29
|
-
BriefReport,
|
|
30
|
-
SurveyListReport,
|
|
31
|
-
TrailDetailReport,
|
|
32
|
-
} from '../trails/survey.js';
|
|
33
|
-
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
|
-
// Test fixtures
|
|
36
|
-
// ---------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
const helloTrail = trail('hello', {
|
|
39
|
-
blaze: (input) => {
|
|
40
|
-
const name = input.name ?? 'world';
|
|
41
|
-
return Result.ok({ message: `Hello, ${name}!` });
|
|
42
|
-
},
|
|
43
|
-
description: 'Say hello',
|
|
44
|
-
detours: [
|
|
45
|
-
{
|
|
46
|
-
on: ConflictError,
|
|
47
|
-
/* oxlint-disable-next-line require-await -- test stub */
|
|
48
|
-
recover: async () => Result.ok({ message: 'recovered' }),
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
examples: [
|
|
52
|
-
{
|
|
53
|
-
expected: { message: 'Hello, world!' },
|
|
54
|
-
input: {},
|
|
55
|
-
name: 'Default greeting',
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
input: z.object({ name: z.string().optional() }),
|
|
59
|
-
intent: 'read',
|
|
60
|
-
output: z.object({ message: z.string() }),
|
|
61
|
-
resources: [
|
|
62
|
-
resource('db.main', {
|
|
63
|
-
create: () => Result.ok({ source: 'factory' }),
|
|
64
|
-
}),
|
|
65
|
-
],
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const byeTrail = trail('bye', {
|
|
69
|
-
blaze: (input) => Result.ok({ message: `Goodbye, ${input.name}!` }),
|
|
70
|
-
description: 'Say goodbye',
|
|
71
|
-
input: z.object({ name: z.string() }),
|
|
72
|
-
output: z.object({ message: z.string() }),
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const [dbResource] = helloTrail.resources;
|
|
76
|
-
if (!dbResource) {
|
|
77
|
-
throw new Error('Expected helloTrail to declare db.main');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const app = topo('test-app', {
|
|
81
|
-
bye: byeTrail,
|
|
82
|
-
dbResource,
|
|
83
|
-
hello: helloTrail,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const expectOk = <T>(result: Result<T, Error>): T => {
|
|
87
|
-
if (result.isErr()) {
|
|
88
|
-
throw result.error;
|
|
89
|
-
}
|
|
90
|
-
return result.value;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const writeSurveyAppFixture = (
|
|
94
|
-
dir: string,
|
|
95
|
-
options?: { withBye?: boolean }
|
|
96
|
-
) => {
|
|
97
|
-
mkdirSync(join(dir, 'src'), { recursive: true });
|
|
98
|
-
const byeSource = options?.withBye
|
|
99
|
-
? `
|
|
100
|
-
const bye = trail('bye', {
|
|
101
|
-
blaze: async (input) => Result.ok({ message: \`Bye, \${input.name ?? 'world'}!\` }),
|
|
102
|
-
input: z.object({ name: z.string().optional() }),
|
|
103
|
-
intent: 'read',
|
|
104
|
-
output: z.object({ message: z.string() }),
|
|
105
|
-
});
|
|
106
|
-
`
|
|
107
|
-
: '';
|
|
108
|
-
const topoMembers = options?.withBye
|
|
109
|
-
? '{ bye, dbMain, hello }'
|
|
110
|
-
: '{ dbMain, hello }';
|
|
111
|
-
writeFileSync(
|
|
112
|
-
join(dir, 'src', 'app.ts'),
|
|
113
|
-
`import { Result, resource, topo, trail } from '@ontrails/core';
|
|
114
|
-
import { z } from 'zod';
|
|
115
|
-
|
|
116
|
-
const hello = trail('hello', {
|
|
117
|
-
blaze: async (input) => Result.ok({ message: \`Hello, \${input.name ?? 'world'}!\` }),
|
|
118
|
-
input: z.object({ name: z.string().optional() }),
|
|
119
|
-
intent: 'read',
|
|
120
|
-
output: z.object({ message: z.string() }),
|
|
121
|
-
resources: [
|
|
122
|
-
resource('db.main', {
|
|
123
|
-
create: () => Result.ok({ source: 'factory' }),
|
|
124
|
-
}),
|
|
125
|
-
],
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const [dbMain] = hello.resources;
|
|
129
|
-
if (!dbMain) {
|
|
130
|
-
throw new Error('expected hello to declare db.main');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
${byeSource}
|
|
134
|
-
|
|
135
|
-
export const app = topo('survey-fixture', ${topoMembers});
|
|
136
|
-
`
|
|
137
|
-
);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const repoTempDir = (): string =>
|
|
141
|
-
join(
|
|
142
|
-
resolve(import.meta.dir, '../..'),
|
|
143
|
-
'.tmp-tests',
|
|
144
|
-
`trails-survey-${Date.now()}-${Math.random().toString(36).slice(2)}`
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
// ---------------------------------------------------------------------------
|
|
148
|
-
// Tests
|
|
149
|
-
// ---------------------------------------------------------------------------
|
|
150
|
-
|
|
151
|
-
describe('trails survey', () => {
|
|
152
|
-
test('deriveSurfaceMap includes all trails', () => {
|
|
153
|
-
const surfaceMap = deriveSurfaceMap(app);
|
|
154
|
-
expect(surfaceMap.entries.length).toBe(3);
|
|
155
|
-
const ids = surfaceMap.entries.map((e) => e.id);
|
|
156
|
-
expect(ids).toContain('hello');
|
|
157
|
-
expect(ids).toContain('bye');
|
|
158
|
-
expect(ids).toContain('db.main');
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
test('surface map entries have expected fields', () => {
|
|
162
|
-
const surfaceMap = deriveSurfaceMap(app);
|
|
163
|
-
const hello = surfaceMap.entries.find((e) => e.id === 'hello');
|
|
164
|
-
expect(hello).toBeDefined();
|
|
165
|
-
expect(hello?.cli?.path).toEqual(['hello']);
|
|
166
|
-
expect(hello?.kind).toBe('trail');
|
|
167
|
-
expect(hello?.intent).toBe('read');
|
|
168
|
-
expect(hello?.exampleCount).toBe(1);
|
|
169
|
-
expect(hello?.resources).toEqual(['db.main']);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test('JSON output is valid JSON', () => {
|
|
173
|
-
const surfaceMap = deriveSurfaceMap(app);
|
|
174
|
-
const json = JSON.stringify(surfaceMap, null, 2);
|
|
175
|
-
const parsed = JSON.parse(json) as SurfaceMap;
|
|
176
|
-
expect(parsed.version).toBe('1.0');
|
|
177
|
-
expect(parsed.entries.length).toBe(3);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test('deriveSurfaceMapHash produces stable hash', () => {
|
|
181
|
-
const surfaceMap = deriveSurfaceMap(app);
|
|
182
|
-
const hash1 = deriveSurfaceMapHash(surfaceMap);
|
|
183
|
-
const hash2 = deriveSurfaceMapHash(surfaceMap);
|
|
184
|
-
expect(hash1).toBe(hash2);
|
|
185
|
-
// SHA-256 hex
|
|
186
|
-
expect(hash1.length).toBe(64);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test('deriveSurfaceMapDiff detects added trails', () => {
|
|
190
|
-
const prev = deriveSurfaceMap(topo('test', { hello: helloTrail }));
|
|
191
|
-
const curr = deriveSurfaceMap(app);
|
|
192
|
-
const diff = deriveSurfaceMapDiff(prev, curr);
|
|
193
|
-
|
|
194
|
-
expect(diff.info.length).toBeGreaterThan(0);
|
|
195
|
-
const addedBye = diff.info.find((e) => e.id === 'bye');
|
|
196
|
-
expect(addedBye).toBeDefined();
|
|
197
|
-
expect(addedBye?.change).toBe('added');
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
test('deriveSurfaceMapDiff detects removed trails', () => {
|
|
201
|
-
const prev = deriveSurfaceMap(app);
|
|
202
|
-
const curr = deriveSurfaceMap(topo('test', { hello: helloTrail }));
|
|
203
|
-
const diff = deriveSurfaceMapDiff(prev, curr);
|
|
204
|
-
|
|
205
|
-
expect(diff.hasBreaking).toBe(true);
|
|
206
|
-
const removedBye = diff.breaking.find((e) => e.id === 'bye');
|
|
207
|
-
expect(removedBye).toBeDefined();
|
|
208
|
-
expect(removedBye?.change).toBe('removed');
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
test('deriveSurfaceMapDiff returns empty for identical maps', () => {
|
|
212
|
-
const surfaceMap = deriveSurfaceMap(app);
|
|
213
|
-
const diff = deriveSurfaceMapDiff(surfaceMap, surfaceMap);
|
|
214
|
-
expect(diff.entries.length).toBe(0);
|
|
215
|
-
expect(diff.hasBreaking).toBe(false);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
// ---------------------------------------------------------------------------
|
|
220
|
-
// Brief mode (formerly scout)
|
|
221
|
-
// ---------------------------------------------------------------------------
|
|
222
|
-
|
|
223
|
-
describe('trails survey --brief', () => {
|
|
224
|
-
test('produces a valid capability report', () => {
|
|
225
|
-
const report = deriveBriefReport(app);
|
|
226
|
-
expect(report.name).toBe('test-app');
|
|
227
|
-
expect(report.contractVersion).toBe('2026-03');
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
test('report includes correct trail count', () => {
|
|
231
|
-
const report = deriveBriefReport(app);
|
|
232
|
-
expect(report.trails).toBe(2);
|
|
233
|
-
expect(report.signals).toBe(0);
|
|
234
|
-
expect(report.resources).toBe(1);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
test('detects features in use', () => {
|
|
238
|
-
const report = deriveBriefReport(app);
|
|
239
|
-
expect(report.features.outputSchemas).toBe(true);
|
|
240
|
-
expect(report.features.examples).toBe(true);
|
|
241
|
-
expect(report.features.detours).toBe(true);
|
|
242
|
-
expect(report.features.signals).toBe(false);
|
|
243
|
-
expect(report.features.resources).toBe(true);
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
test('JSON output is valid', () => {
|
|
247
|
-
const report = deriveBriefReport(app);
|
|
248
|
-
const json = JSON.stringify(report, null, 2);
|
|
249
|
-
const parsed = JSON.parse(json) as BriefReport;
|
|
250
|
-
expect(parsed.name).toBe('test-app');
|
|
251
|
-
expect(parsed.trails).toBe(2);
|
|
252
|
-
expect(parsed.resources).toBe(1);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
test('empty app reports zero features', () => {
|
|
256
|
-
const emptyApp = topo('empty', {});
|
|
257
|
-
const report = deriveBriefReport(emptyApp);
|
|
258
|
-
expect(report.trails).toBe(0);
|
|
259
|
-
expect(report.features.outputSchemas).toBe(false);
|
|
260
|
-
expect(report.features.examples).toBe(false);
|
|
261
|
-
expect(report.features.detours).toBe(false);
|
|
262
|
-
expect(report.features.resources).toBe(false);
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
describe('trails survey detail', () => {
|
|
267
|
-
test('trail detail includes declared resources, crossings, and intent', () => {
|
|
268
|
-
const detail = deriveTrailDetail(helloTrail);
|
|
269
|
-
const parsed = structuredClone(detail) as TrailDetailReport;
|
|
270
|
-
|
|
271
|
-
expect(parsed.crosses).toEqual([]);
|
|
272
|
-
expect(parsed.intent).toBe('read');
|
|
273
|
-
expect(parsed.resources).toEqual(['db.main']);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
describe('trails survey resources section', () => {
|
|
278
|
-
test('list output includes resource lifetime and health status', () => {
|
|
279
|
-
const report = deriveSurveyList(app);
|
|
280
|
-
const parsed = structuredClone(report) as SurveyListReport;
|
|
281
|
-
const db = parsed.resources.find((entry) => entry.id === 'db.main');
|
|
282
|
-
|
|
283
|
-
expect(parsed.resourceCount).toBe(1);
|
|
284
|
-
expect(db).toEqual({
|
|
285
|
-
description: null,
|
|
286
|
-
health: 'none',
|
|
287
|
-
id: 'db.main',
|
|
288
|
-
kind: 'resource',
|
|
289
|
-
lifetime: 'singleton',
|
|
290
|
-
usedBy: ['hello'],
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
describe('trails survey generate', () => {
|
|
296
|
-
test('delegates to topo export and writes a structured lock', async () => {
|
|
297
|
-
const dir = repoTempDir();
|
|
298
|
-
|
|
299
|
-
try {
|
|
300
|
-
writeSurveyAppFixture(dir);
|
|
301
|
-
|
|
302
|
-
const generated = expectOk(
|
|
303
|
-
await surveyTrail.blaze({ generate: true, module: './src/app.ts' }, {
|
|
304
|
-
cwd: dir,
|
|
305
|
-
} as never)
|
|
306
|
-
) as {
|
|
307
|
-
readonly hash: string;
|
|
308
|
-
readonly lockPath: string;
|
|
309
|
-
readonly mapPath: string;
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
expect(generated.hash).toHaveLength(64);
|
|
313
|
-
expect(existsSync(join(dir, '.trails', '_surface.json'))).toBe(true);
|
|
314
|
-
expect(existsSync(join(dir, '.trails', 'trails.lock'))).toBe(true);
|
|
315
|
-
expect(
|
|
316
|
-
JSON.parse(readFileSync(join(dir, '.trails', 'trails.lock'), 'utf8'))
|
|
317
|
-
).toMatchObject({
|
|
318
|
-
hash: generated.hash,
|
|
319
|
-
version: 1,
|
|
320
|
-
});
|
|
321
|
-
} finally {
|
|
322
|
-
rmSync(dir, { force: true, recursive: true });
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
describe('trails survey diffSaved', () => {
|
|
328
|
-
test('returns an error when no saved surface map exists yet', async () => {
|
|
329
|
-
const dir = repoTempDir();
|
|
330
|
-
|
|
331
|
-
try {
|
|
332
|
-
writeSurveyAppFixture(dir);
|
|
333
|
-
|
|
334
|
-
const result = await surveyTrail.blaze(
|
|
335
|
-
{ diffSaved: true, module: './src/app.ts' },
|
|
336
|
-
{ cwd: dir } as never
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
expect(result.isErr()).toBe(true);
|
|
340
|
-
expect(result.error.message).toContain('Run `trails topo export` first');
|
|
341
|
-
} finally {
|
|
342
|
-
rmSync(dir, { force: true, recursive: true });
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
test('diffs against the saved local surface map', async () => {
|
|
347
|
-
const dir = repoTempDir();
|
|
348
|
-
|
|
349
|
-
try {
|
|
350
|
-
writeSurveyAppFixture(dir);
|
|
351
|
-
const baselineApp = await loadApp('./src/app.ts', dir);
|
|
352
|
-
await writeSurfaceMap(deriveSurfaceMap(baselineApp), {
|
|
353
|
-
dir: join(dir, '.trails'),
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
writeSurveyAppFixture(dir, { withBye: true });
|
|
357
|
-
|
|
358
|
-
const result = await surveyTrail.blaze(
|
|
359
|
-
{ diffSaved: true, module: './src/app.ts' },
|
|
360
|
-
{ cwd: dir } as never
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
expect(result.isOk()).toBe(true);
|
|
364
|
-
expect(result.value).toMatchObject({
|
|
365
|
-
hasBreaking: false,
|
|
366
|
-
info: [
|
|
367
|
-
expect.objectContaining({
|
|
368
|
-
change: 'added',
|
|
369
|
-
id: 'bye',
|
|
370
|
-
}),
|
|
371
|
-
],
|
|
372
|
-
});
|
|
373
|
-
} finally {
|
|
374
|
-
rmSync(dir, { force: true, recursive: true });
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
});
|