@quickback-dev/cli 0.66.14 → 0.66.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/dist/commands/schema.d.ts +1 -1
- package/dist/commands/schema.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/action-harvest.d.ts.map +1 -1
- package/dist/lib/action-harvest.js +28 -7
- package/dist/lib/action-harvest.js.map +1 -1
- package/dist/lib/file-loader.js +1 -1
- package/dist/lib/file-loader.js.map +1 -1
- package/dist/lib/migrations/file-envelopes.d.ts.map +1 -1
- package/dist/lib/migrations/file-envelopes.js +79 -4
- package/dist/lib/migrations/file-envelopes.js.map +1 -1
- package/dist/lib/migrations/staging.js.map +1 -1
- package/dist/lib/schema-sync/index.d.ts +1 -1
- package/dist/lib/schema-sync/index.d.ts.map +1 -1
- package/dist/lib/schema-sync/index.js +10 -4
- package/dist/lib/schema-sync/index.js.map +1 -1
- package/dist/schema-engine/index.js.map +1 -1
- package/dist/schema-engine/source-sync.d.ts +1 -1
- package/dist/schema-engine/source-sync.d.ts.map +1 -1
- package/dist/skill/docs/api/batch-operations.md +1 -1
- package/dist/skill/docs/api/typescript.md +102 -4
- package/dist/skill/docs/define/actions/defining.md +23 -11
- package/dist/skill/docs/define/feature.md +10 -0
- package/dist/skill/docs/define/masking.md +13 -0
- package/dist/skill/docs/define/schema.md +9 -1
- package/dist/skill/docs/index.md +2 -0
- package/dist/skill/docs/platform/auth/plugins/aws-ses.md +5 -0
- package/dist/skill/docs/tooling/cli.md +3 -1
- package/dist/skill/docs/tooling/cloud-compiler/local-compiler.md +17 -0
- package/dist/skill/docs/ui/account/environment-variables.md +5 -4
- package/dist/skill/docs/ui/account/features/index.md +14 -9
- package/dist/skill/docs/ui/account/hooks.md +12 -5
- package/package.json +1 -1
- package/src/skill/docs/api/batch-operations.md +1 -1
- package/src/skill/docs/api/typescript.md +102 -4
- package/src/skill/docs/define/actions/defining.md +23 -11
- package/src/skill/docs/define/feature.md +10 -0
- package/src/skill/docs/define/masking.md +13 -0
- package/src/skill/docs/define/schema.md +9 -1
- package/src/skill/docs/index.md +2 -0
- package/src/skill/docs/platform/auth/plugins/aws-ses.md +5 -0
- package/src/skill/docs/tooling/cli.md +3 -1
- package/src/skill/docs/tooling/cloud-compiler/local-compiler.md +17 -0
- package/src/skill/docs/ui/account/environment-variables.md +5 -4
- package/src/skill/docs/ui/account/features/index.md +14 -9
- package/src/skill/docs/ui/account/hooks.md +12 -5
- package/dist/commands/build.test.d.ts +0 -2
- package/dist/commands/build.test.d.ts.map +0 -1
- package/dist/commands/build.test.js +0 -201
- package/dist/commands/build.test.js.map +0 -1
- package/dist/commands/canary.test.d.ts +0 -2
- package/dist/commands/canary.test.d.ts.map +0 -1
- package/dist/commands/canary.test.js +0 -100
- package/dist/commands/canary.test.js.map +0 -1
- package/dist/commands/deploy.test.d.ts +0 -2
- package/dist/commands/deploy.test.d.ts.map +0 -1
- package/dist/commands/deploy.test.js +0 -139
- package/dist/commands/deploy.test.js.map +0 -1
- package/dist/commands/migrate.test.d.ts +0 -2
- package/dist/commands/migrate.test.d.ts.map +0 -1
- package/dist/commands/migrate.test.js +0 -283
- package/dist/commands/migrate.test.js.map +0 -1
- package/dist/commands/migrations.test.d.ts +0 -2
- package/dist/commands/migrations.test.d.ts.map +0 -1
- package/dist/commands/migrations.test.js +0 -162
- package/dist/commands/migrations.test.js.map +0 -1
- package/dist/commands/push.test.d.ts +0 -2
- package/dist/commands/push.test.d.ts.map +0 -1
- package/dist/commands/push.test.js +0 -76
- package/dist/commands/push.test.js.map +0 -1
- package/dist/commands/schema.test.d.ts +0 -2
- package/dist/commands/schema.test.d.ts.map +0 -1
- package/dist/commands/schema.test.js +0 -137
- package/dist/commands/schema.test.js.map +0 -1
- package/dist/docs/index.test.d.ts +0 -2
- package/dist/docs/index.test.d.ts.map +0 -1
- package/dist/docs/index.test.js +0 -51
- package/dist/docs/index.test.js.map +0 -1
- package/dist/lib/action-harvest.test.d.ts +0 -2
- package/dist/lib/action-harvest.test.d.ts.map +0 -1
- package/dist/lib/action-harvest.test.js +0 -645
- package/dist/lib/action-harvest.test.js.map +0 -1
- package/dist/lib/api-client.test.d.ts +0 -2
- package/dist/lib/api-client.test.d.ts.map +0 -1
- package/dist/lib/api-client.test.js +0 -373
- package/dist/lib/api-client.test.js.map +0 -1
- package/dist/lib/artifact-routing.test.d.ts +0 -2
- package/dist/lib/artifact-routing.test.d.ts.map +0 -1
- package/dist/lib/artifact-routing.test.js +0 -48
- package/dist/lib/artifact-routing.test.js.map +0 -1
- package/dist/lib/auth.test.d.ts +0 -2
- package/dist/lib/auth.test.d.ts.map +0 -1
- package/dist/lib/auth.test.js +0 -19
- package/dist/lib/auth.test.js.map +0 -1
- package/dist/lib/compile-next-steps.test.d.ts +0 -2
- package/dist/lib/compile-next-steps.test.d.ts.map +0 -1
- package/dist/lib/compile-next-steps.test.js +0 -76
- package/dist/lib/compile-next-steps.test.js.map +0 -1
- package/dist/lib/compiler-floor.test.d.ts +0 -2
- package/dist/lib/compiler-floor.test.d.ts.map +0 -1
- package/dist/lib/compiler-floor.test.js +0 -67
- package/dist/lib/compiler-floor.test.js.map +0 -1
- package/dist/lib/config-id-splice.test.d.ts +0 -2
- package/dist/lib/config-id-splice.test.d.ts.map +0 -1
- package/dist/lib/config-id-splice.test.js +0 -246
- package/dist/lib/config-id-splice.test.js.map +0 -1
- package/dist/lib/config-sync.test.d.ts +0 -2
- package/dist/lib/config-sync.test.d.ts.map +0 -1
- package/dist/lib/config-sync.test.js +0 -151
- package/dist/lib/config-sync.test.js.map +0 -1
- package/dist/lib/copy-public-assets.test.d.ts +0 -2
- package/dist/lib/copy-public-assets.test.d.ts.map +0 -1
- package/dist/lib/copy-public-assets.test.js +0 -151
- package/dist/lib/copy-public-assets.test.js.map +0 -1
- package/dist/lib/copy-source-apps.test.d.ts +0 -2
- package/dist/lib/copy-source-apps.test.d.ts.map +0 -1
- package/dist/lib/copy-source-apps.test.js +0 -170
- package/dist/lib/copy-source-apps.test.js.map +0 -1
- package/dist/lib/deployment-target.test.d.ts +0 -2
- package/dist/lib/deployment-target.test.d.ts.map +0 -1
- package/dist/lib/deployment-target.test.js +0 -63
- package/dist/lib/deployment-target.test.js.map +0 -1
- package/dist/lib/drizzle-meta-routing.test.d.ts +0 -2
- package/dist/lib/drizzle-meta-routing.test.d.ts.map +0 -1
- package/dist/lib/drizzle-meta-routing.test.js +0 -136
- package/dist/lib/drizzle-meta-routing.test.js.map +0 -1
- package/dist/lib/file-loader-typescript-fallback.test.d.ts +0 -2
- package/dist/lib/file-loader-typescript-fallback.test.d.ts.map +0 -1
- package/dist/lib/file-loader-typescript-fallback.test.js +0 -58
- package/dist/lib/file-loader-typescript-fallback.test.js.map +0 -1
- package/dist/lib/file-loader.test.d.ts +0 -2
- package/dist/lib/file-loader.test.d.ts.map +0 -1
- package/dist/lib/file-loader.test.js +0 -475
- package/dist/lib/file-loader.test.js.map +0 -1
- package/dist/lib/file-writer.test.d.ts +0 -2
- package/dist/lib/file-writer.test.d.ts.map +0 -1
- package/dist/lib/file-writer.test.js +0 -131
- package/dist/lib/file-writer.test.js.map +0 -1
- package/dist/lib/migrations/command-runner.test.d.ts +0 -2
- package/dist/lib/migrations/command-runner.test.d.ts.map +0 -1
- package/dist/lib/migrations/command-runner.test.js +0 -19
- package/dist/lib/migrations/command-runner.test.js.map +0 -1
- package/dist/lib/migrations/drizzle-prompts.test.d.ts +0 -2
- package/dist/lib/migrations/drizzle-prompts.test.d.ts.map +0 -1
- package/dist/lib/migrations/drizzle-prompts.test.js +0 -135
- package/dist/lib/migrations/drizzle-prompts.test.js.map +0 -1
- package/dist/lib/migrations/drizzle-wrapper.test.d.ts +0 -2
- package/dist/lib/migrations/drizzle-wrapper.test.d.ts.map +0 -1
- package/dist/lib/migrations/drizzle-wrapper.test.js +0 -64
- package/dist/lib/migrations/drizzle-wrapper.test.js.map +0 -1
- package/dist/lib/migrations/drizzle.test.d.ts +0 -2
- package/dist/lib/migrations/drizzle.test.d.ts.map +0 -1
- package/dist/lib/migrations/drizzle.test.js +0 -71
- package/dist/lib/migrations/drizzle.test.js.map +0 -1
- package/dist/lib/migrations/executor.test.d.ts +0 -2
- package/dist/lib/migrations/executor.test.d.ts.map +0 -1
- package/dist/lib/migrations/executor.test.js +0 -270
- package/dist/lib/migrations/executor.test.js.map +0 -1
- package/dist/lib/migrations/headless-generate.test.d.ts +0 -2
- package/dist/lib/migrations/headless-generate.test.d.ts.map +0 -1
- package/dist/lib/migrations/headless-generate.test.js +0 -167
- package/dist/lib/migrations/headless-generate.test.js.map +0 -1
- package/dist/lib/migrations/inventory.test.d.ts +0 -2
- package/dist/lib/migrations/inventory.test.d.ts.map +0 -1
- package/dist/lib/migrations/inventory.test.js +0 -81
- package/dist/lib/migrations/inventory.test.js.map +0 -1
- package/dist/lib/migrations/lock.test.d.ts +0 -2
- package/dist/lib/migrations/lock.test.d.ts.map +0 -1
- package/dist/lib/migrations/lock.test.js +0 -35
- package/dist/lib/migrations/lock.test.js.map +0 -1
- package/dist/lib/migrations/paths.test.d.ts +0 -2
- package/dist/lib/migrations/paths.test.d.ts.map +0 -1
- package/dist/lib/migrations/paths.test.js +0 -32
- package/dist/lib/migrations/paths.test.js.map +0 -1
- package/dist/lib/migrations/plan.test.d.ts +0 -2
- package/dist/lib/migrations/plan.test.d.ts.map +0 -1
- package/dist/lib/migrations/plan.test.js +0 -104
- package/dist/lib/migrations/plan.test.js.map +0 -1
- package/dist/lib/migrations/postprocessors/index.test.d.ts +0 -2
- package/dist/lib/migrations/postprocessors/index.test.d.ts.map +0 -1
- package/dist/lib/migrations/postprocessors/index.test.js +0 -393
- package/dist/lib/migrations/postprocessors/index.test.js.map +0 -1
- package/dist/lib/migrations/prompt-runner.test.d.ts +0 -2
- package/dist/lib/migrations/prompt-runner.test.d.ts.map +0 -1
- package/dist/lib/migrations/prompt-runner.test.js +0 -135
- package/dist/lib/migrations/prompt-runner.test.js.map +0 -1
- package/dist/lib/migrations/staging.test.d.ts +0 -2
- package/dist/lib/migrations/staging.test.d.ts.map +0 -1
- package/dist/lib/migrations/staging.test.js +0 -73
- package/dist/lib/migrations/staging.test.js.map +0 -1
- package/dist/lib/neon-canary.test.d.ts +0 -2
- package/dist/lib/neon-canary.test.d.ts.map +0 -1
- package/dist/lib/neon-canary.test.js +0 -186
- package/dist/lib/neon-canary.test.js.map +0 -1
- package/dist/lib/neon-target.test.d.ts +0 -2
- package/dist/lib/neon-target.test.d.ts.map +0 -1
- package/dist/lib/neon-target.test.js +0 -122
- package/dist/lib/neon-target.test.js.map +0 -1
- package/dist/lib/neon.test.d.ts +0 -2
- package/dist/lib/neon.test.d.ts.map +0 -1
- package/dist/lib/neon.test.js +0 -154
- package/dist/lib/neon.test.js.map +0 -1
- package/dist/lib/prepare-output.test.d.ts +0 -2
- package/dist/lib/prepare-output.test.d.ts.map +0 -1
- package/dist/lib/prepare-output.test.js +0 -105
- package/dist/lib/prepare-output.test.js.map +0 -1
- package/dist/lib/prepare-state-output.test.d.ts +0 -2
- package/dist/lib/prepare-state-output.test.d.ts.map +0 -1
- package/dist/lib/prepare-state-output.test.js +0 -111
- package/dist/lib/prepare-state-output.test.js.map +0 -1
- package/dist/lib/schema-sync/index.test.d.ts +0 -2
- package/dist/lib/schema-sync/index.test.d.ts.map +0 -1
- package/dist/lib/schema-sync/index.test.js +0 -216
- package/dist/lib/schema-sync/index.test.js.map +0 -1
- package/dist/lib/shell.test.d.ts +0 -2
- package/dist/lib/shell.test.d.ts.map +0 -1
- package/dist/lib/shell.test.js +0 -73
- package/dist/lib/shell.test.js.map +0 -1
- package/dist/lib/wrangler-resources.test.d.ts +0 -2
- package/dist/lib/wrangler-resources.test.d.ts.map +0 -1
- package/dist/lib/wrangler-resources.test.js +0 -347
- package/dist/lib/wrangler-resources.test.js.map +0 -1
|
@@ -1,645 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI action-input harvester — fidelity + robustness.
|
|
3
|
-
*
|
|
4
|
-
* This is where the high-fidelity guarantee lives now: harvesting runs on the
|
|
5
|
-
* user's machine (the compiler never executes user code). We stage a tiny
|
|
6
|
-
* project with real action files, run the harvester, and assert that
|
|
7
|
-
* `z.toJSONSchema` shapes the regex/static parser can't produce
|
|
8
|
-
* (discriminated unions → oneOf, refinement bounds → minLength/maximum, etc.)
|
|
9
|
-
* round-trip into the returned schema map, keyed by compiler staging path.
|
|
10
|
-
*/
|
|
11
|
-
import { describe, expect, test, afterEach } from 'bun:test';
|
|
12
|
-
import { mkdir, writeFile, rm, symlink } from 'fs/promises';
|
|
13
|
-
import { existsSync } from 'fs';
|
|
14
|
-
import { join, resolve } from 'path';
|
|
15
|
-
import { tmpdir } from 'os';
|
|
16
|
-
import { randomUUID } from 'crypto';
|
|
17
|
-
import { harvestActionInputSchemas, harvestActionInputSchemasDetailed, missingActionInputSchemaKeys, } from './action-harvest.js';
|
|
18
|
-
import { loadFeatures } from './file-loader.js';
|
|
19
|
-
const TMP_BASE = resolve(__dirname, '..', '..', '.test-tmp-cli');
|
|
20
|
-
// The CLI package vendors an old zod that esbuild would otherwise resolve;
|
|
21
|
-
// point staged projects at the repo-root Zod 4 (which has `z.toJSONSchema`),
|
|
22
|
-
// mirroring a real user project that installs Zod 4. Nearest node_modules wins.
|
|
23
|
-
// Resolve real Zod 4 + drizzle-orm from the first location that actually has
|
|
24
|
-
// them. Prefer the STABLE, always-complete examples/recruitment install over a
|
|
25
|
-
// bare repo-root node_modules: a plain `bun test` runs files in parallel, and
|
|
26
|
-
// another test that transiently stages a repo-root node_modules would otherwise
|
|
27
|
-
// race a module-load existsSync check on that path (flaky pass/fail). CI's
|
|
28
|
-
// hoisted repo-root install is the fallback; a bare git worktree with neither
|
|
29
|
-
// makes the nested-outputDir regression skip (below), never false-fail.
|
|
30
|
-
function firstExistingDir(...candidates) {
|
|
31
|
-
for (const c of candidates)
|
|
32
|
-
if (existsSync(c))
|
|
33
|
-
return c;
|
|
34
|
-
return candidates[candidates.length - 1];
|
|
35
|
-
}
|
|
36
|
-
const REPO_ZOD = firstExistingDir(resolve(__dirname, '..', '..', '..', '..', 'examples', 'recruitment', 'node_modules', 'zod'), resolve(__dirname, '..', '..', '..', '..', 'node_modules', 'zod'));
|
|
37
|
-
const REPO_DRIZZLE = firstExistingDir(resolve(__dirname, '..', '..', '..', '..', 'examples', 'recruitment', 'node_modules', 'drizzle-orm'), resolve(__dirname, '..', '..', '..', '..', 'node_modules', 'drizzle-orm'));
|
|
38
|
-
// The nested-outputDir regression deliberately isolates its project outside the
|
|
39
|
-
// checkout, so it relies SOLELY on the real Zod 4 + drizzle-orm resolved above.
|
|
40
|
-
// Skip (never fail) when neither install is materialized, mirroring the
|
|
41
|
-
// env-gated pattern the real-Neon tests use. stageProject-based tests are
|
|
42
|
-
// immune: their projects sit under the checkout and resolve deps by upward
|
|
43
|
-
// discovery.
|
|
44
|
-
const HAS_REPO_ROOT_DEPS = existsSync(REPO_ZOD) && existsSync(REPO_DRIZZLE);
|
|
45
|
-
if (!HAS_REPO_ROOT_DEPS) {
|
|
46
|
-
console.warn('[action-harvest] SKIP: nested-outputDir regression needs real zod@4 + drizzle-orm at the ' +
|
|
47
|
-
'repo root (run a full workspace install). Skipping — not a product failure.');
|
|
48
|
-
}
|
|
49
|
-
const stagedDirs = [];
|
|
50
|
-
afterEach(async () => {
|
|
51
|
-
for (const dir of stagedDirs.splice(0)) {
|
|
52
|
-
await rm(dir, { recursive: true, force: true });
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
describe('missingActionInputSchemaKeys — strict v2 completeness', () => {
|
|
56
|
-
test('reports stable staging keys for partial harvests', () => {
|
|
57
|
-
const features = [
|
|
58
|
-
{
|
|
59
|
-
name: 'passes',
|
|
60
|
-
actionFiles: {
|
|
61
|
-
'actions/redeem.ts': '',
|
|
62
|
-
'actions/rotate.ts': '',
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
];
|
|
66
|
-
expect(missingActionInputSchemaKeys(features, {
|
|
67
|
-
'src/features/passes/actions/redeem.ts': { type: 'object' },
|
|
68
|
-
})).toEqual(['src/features/passes/actions/rotate.ts']);
|
|
69
|
-
expect(missingActionInputSchemaKeys(features, {
|
|
70
|
-
'src/features/passes/actions/redeem.ts': { type: 'object' },
|
|
71
|
-
'src/features/passes/actions/rotate.ts': { type: 'object' },
|
|
72
|
-
})).toEqual([]);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
async function stageProject(actionFiles) {
|
|
76
|
-
const projectRoot = join(TMP_BASE, `proj-${randomUUID().slice(0, 8)}`);
|
|
77
|
-
stagedDirs.push(projectRoot);
|
|
78
|
-
const featuresDir = join(projectRoot, 'features');
|
|
79
|
-
for (const [rel, content] of Object.entries(actionFiles)) {
|
|
80
|
-
const full = join(featuresDir, rel);
|
|
81
|
-
await mkdir(join(full, '..'), { recursive: true });
|
|
82
|
-
await writeFile(full, content, 'utf-8');
|
|
83
|
-
}
|
|
84
|
-
// Make `import { z } from 'zod'` resolve to Zod 4 from the project root.
|
|
85
|
-
await mkdir(join(projectRoot, 'node_modules'), { recursive: true });
|
|
86
|
-
await symlink(REPO_ZOD, join(projectRoot, 'node_modules', 'zod'), 'dir');
|
|
87
|
-
// drizzle-orm too, so an action importing it (like real ones do) bundles —
|
|
88
|
-
// and we exercise that its INTERNAL relative imports aren't wrongly stubbed.
|
|
89
|
-
await symlink(REPO_DRIZZLE, join(projectRoot, 'node_modules', 'drizzle-orm'), 'dir').catch(() => { });
|
|
90
|
-
return { projectRoot, featuresDir };
|
|
91
|
-
}
|
|
92
|
-
describe('harvestActionInputSchemas — runs locally, produces high-fidelity schemas', () => {
|
|
93
|
-
test.each([
|
|
94
|
-
['', `guests: list('guests', { columns: ['id'], limit: 500 })`],
|
|
95
|
-
['.ts', `counts: custom(() => { markHandlerRun(); return { open: 0 }; })`],
|
|
96
|
-
['.js', `guests: list('guests'), counts: custom(async () => { markHandlerRun(); return { open: 0 }; })`],
|
|
97
|
-
])('harvests canonical bundle input with helper suffix "%s" without running sections', async (suffix, sections) => {
|
|
98
|
-
const { projectRoot, featuresDir } = await stageProject({ 'events/actions/getBundle.ts': '' });
|
|
99
|
-
const sentinel = join(projectRoot, 'handler-ran');
|
|
100
|
-
const action = `
|
|
101
|
-
import { defineBundle, list, custom } from '../.quickback/define-bundle${suffix}';
|
|
102
|
-
import { writeFileSync } from 'node:fs';
|
|
103
|
-
function markHandlerRun() { writeFileSync(${JSON.stringify(sentinel)}, 'ran'); }
|
|
104
|
-
export default defineBundle({
|
|
105
|
-
description: 'Overview bootstrap',
|
|
106
|
-
path: '/event/:eventId/overview-bundle',
|
|
107
|
-
access: { roles: ['member'] },
|
|
108
|
-
sections: { ${sections} },
|
|
109
|
-
});
|
|
110
|
-
`;
|
|
111
|
-
await writeFile(join(featuresDir, 'events/actions/getBundle.ts'), action);
|
|
112
|
-
const features = [{ name: 'events', actionFiles: { 'actions/getBundle.ts': action } }];
|
|
113
|
-
const result = await harvestActionInputSchemasDetailed({ projectRoot, featuresDir, features });
|
|
114
|
-
expect(existsSync(sentinel)).toBe(false);
|
|
115
|
-
expect(result.diagnostics).toEqual([]);
|
|
116
|
-
expect(missingActionInputSchemaKeys(features, result.schemas)).toEqual([]);
|
|
117
|
-
expect(result.schemas['src/features/events/actions/getBundle.ts']).toEqual({
|
|
118
|
-
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
119
|
-
type: 'object',
|
|
120
|
-
properties: {
|
|
121
|
-
sections: { type: 'array', items: { type: 'string' } },
|
|
122
|
-
ifNoneMatch: { type: 'string' },
|
|
123
|
-
},
|
|
124
|
-
additionalProperties: false,
|
|
125
|
-
});
|
|
126
|
-
expect(result.outputSchemas).toEqual({});
|
|
127
|
-
});
|
|
128
|
-
test('harvests declared output schemas beside inputs without executing the action', async () => {
|
|
129
|
-
const action = `
|
|
130
|
-
import { z } from 'zod';
|
|
131
|
-
export default {
|
|
132
|
-
input: z.object({ id: z.string() }),
|
|
133
|
-
output: z.object({ id: z.string(), state: z.enum(['open', 'closed']) }),
|
|
134
|
-
execute: async () => { throw new Error('execute must not run during harvest'); },
|
|
135
|
-
};
|
|
136
|
-
`;
|
|
137
|
-
const { projectRoot, featuresDir } = await stageProject({ 'records/actions/read.ts': action });
|
|
138
|
-
const result = await harvestActionInputSchemasDetailed({
|
|
139
|
-
projectRoot,
|
|
140
|
-
featuresDir,
|
|
141
|
-
features: [{ name: 'records', actionFiles: { 'actions/read.ts': action } }],
|
|
142
|
-
});
|
|
143
|
-
const key = 'src/features/records/actions/read.ts';
|
|
144
|
-
expect(result.schemas[key].properties.id.type).toBe('string');
|
|
145
|
-
expect(result.outputSchemas[key].properties.id.type).toBe('string');
|
|
146
|
-
expect(result.outputSchemas[key].properties.state.enum).toEqual(['open', 'closed']);
|
|
147
|
-
expect(result.diagnostics).toEqual([]);
|
|
148
|
-
});
|
|
149
|
-
test('discriminated union round-trips into oneOf, keyed by staging path', async () => {
|
|
150
|
-
const action = `
|
|
151
|
-
import { z } from 'zod';
|
|
152
|
-
export default {
|
|
153
|
-
input: z.discriminatedUnion('type', [
|
|
154
|
-
z.object({ type: z.literal('note'), text: z.string() }),
|
|
155
|
-
z.object({ type: z.literal('link'), url: z.string().url() }),
|
|
156
|
-
]),
|
|
157
|
-
};
|
|
158
|
-
`;
|
|
159
|
-
const { projectRoot, featuresDir } = await stageProject({ 'records/actions/createRecord.ts': action });
|
|
160
|
-
const schemas = await harvestActionInputSchemas({
|
|
161
|
-
projectRoot,
|
|
162
|
-
featuresDir,
|
|
163
|
-
features: [{ name: 'records', actionFiles: { 'actions/createRecord.ts': action } }],
|
|
164
|
-
});
|
|
165
|
-
const key = 'src/features/records/actions/createRecord.ts';
|
|
166
|
-
const schema = schemas[key];
|
|
167
|
-
expect(schema).toBeDefined();
|
|
168
|
-
expect(Array.isArray(schema.oneOf)).toBe(true);
|
|
169
|
-
expect(schema.oneOf).toHaveLength(2);
|
|
170
|
-
});
|
|
171
|
-
test('refinement + bounds round-trip (shape the static parser drops)', async () => {
|
|
172
|
-
const action = `
|
|
173
|
-
import { z } from 'zod';
|
|
174
|
-
export default {
|
|
175
|
-
input: z.object({
|
|
176
|
-
name: z.string().min(1).max(120),
|
|
177
|
-
age: z.number().int().min(0),
|
|
178
|
-
}).refine((v) => v.age >= 18, { message: 'Adults only.' }),
|
|
179
|
-
};
|
|
180
|
-
`;
|
|
181
|
-
const { projectRoot, featuresDir } = await stageProject({ 'users/actions/createUser.ts': action });
|
|
182
|
-
const schemas = await harvestActionInputSchemas({
|
|
183
|
-
projectRoot,
|
|
184
|
-
featuresDir,
|
|
185
|
-
features: [{ name: 'users', actionFiles: { 'actions/createUser.ts': action } }],
|
|
186
|
-
});
|
|
187
|
-
const schema = schemas['src/features/users/actions/createUser.ts'];
|
|
188
|
-
expect(schema).toBeDefined();
|
|
189
|
-
expect(schema.properties.name.minLength).toBe(1);
|
|
190
|
-
expect(schema.properties.name.maxLength).toBe(120);
|
|
191
|
-
expect(schema.properties.age.type).toBe('integer');
|
|
192
|
-
expect(schema.properties.age.minimum).toBe(0);
|
|
193
|
-
});
|
|
194
|
-
test('a broken action is dropped without taking down the others', async () => {
|
|
195
|
-
const good = `import { z } from 'zod';\nexport default { input: z.object({ ok: z.boolean() }) };\n`;
|
|
196
|
-
const broken = `import { z } from 'zod';\nthrow new Error('load-time boom');\nexport default { input: z.object({}) };\n`;
|
|
197
|
-
const { projectRoot, featuresDir } = await stageProject({
|
|
198
|
-
'f/actions/good.ts': good,
|
|
199
|
-
'f/actions/broken.ts': broken,
|
|
200
|
-
});
|
|
201
|
-
const result = await harvestActionInputSchemasDetailed({
|
|
202
|
-
projectRoot,
|
|
203
|
-
featuresDir,
|
|
204
|
-
features: [{ name: 'f', actionFiles: { 'actions/good.ts': good, 'actions/broken.ts': broken } }],
|
|
205
|
-
});
|
|
206
|
-
const schemas = result.schemas;
|
|
207
|
-
expect(schemas['src/features/f/actions/good.ts']).toBeDefined();
|
|
208
|
-
expect(schemas['src/features/f/actions/broken.ts']).toBeUndefined();
|
|
209
|
-
expect(result.diagnostics).toHaveLength(1);
|
|
210
|
-
expect(result.diagnostics[0]?.key).toBe('src/features/f/actions/broken.ts');
|
|
211
|
-
expect(result.diagnostics[0]?.phase).toBe('evaluation');
|
|
212
|
-
expect(result.diagnostics[0]?.message).toContain('load-time boom');
|
|
213
|
-
});
|
|
214
|
-
test('no action files → empty map, no work', async () => {
|
|
215
|
-
const { projectRoot, featuresDir } = await stageProject({});
|
|
216
|
-
const schemas = await harvestActionInputSchemas({
|
|
217
|
-
projectRoot,
|
|
218
|
-
featuresDir,
|
|
219
|
-
features: [{ name: 'empty', actionFiles: {} }],
|
|
220
|
-
});
|
|
221
|
-
expect(Object.keys(schemas)).toHaveLength(0);
|
|
222
|
-
});
|
|
223
|
-
// Regression (attendvip): a real action imports a COMPILER-GENERATED module
|
|
224
|
-
// with no on-disk source (`../../../lib/types`, where ActionError lives), a
|
|
225
|
-
// generated table export (`../things`), and a real dep (drizzle-orm). Its
|
|
226
|
-
// `input` uses z.union of literals. Previously the unresolvable `lib/types`
|
|
227
|
-
// failed the esbuild bundle → the action was silently dropped to the lossy
|
|
228
|
-
// static fallback (z.union → `{}`). The harvest must now bundle through it and
|
|
229
|
-
// return the high-fidelity schema — and the drizzle dep must NOT be broken by
|
|
230
|
-
// over-stubbing its internal relative imports.
|
|
231
|
-
test('harvests through a generated lib import + drizzle dep + z.union', async () => {
|
|
232
|
-
const action = `
|
|
233
|
-
import { z } from 'zod';
|
|
234
|
-
import { eq } from 'drizzle-orm';
|
|
235
|
-
import { ActionError } from '../../../lib/types';
|
|
236
|
-
import { things } from '../things';
|
|
237
|
-
export default {
|
|
238
|
-
input: z.object({
|
|
239
|
-
flag: z.union([z.literal(0), z.literal(1)]).optional(),
|
|
240
|
-
name: z.string(),
|
|
241
|
-
}),
|
|
242
|
-
execute: async () => { void eq; void things; void ActionError; },
|
|
243
|
-
};
|
|
244
|
-
`;
|
|
245
|
-
const { projectRoot, featuresDir } = await stageProject({ 'agenda/actions/createGroup.ts': action });
|
|
246
|
-
const schemas = await harvestActionInputSchemas({
|
|
247
|
-
projectRoot,
|
|
248
|
-
featuresDir,
|
|
249
|
-
features: [{ name: 'agenda', actionFiles: { 'actions/createGroup.ts': '' } }],
|
|
250
|
-
});
|
|
251
|
-
const schema = schemas['src/features/agenda/actions/createGroup.ts'];
|
|
252
|
-
expect(schema).toBeDefined(); // not dropped
|
|
253
|
-
expect(schema.properties.name.type).toBe('string');
|
|
254
|
-
// z.union([z.literal(0), z.literal(1)]) → faithful (anyOf/enum of 0|1), never {}.
|
|
255
|
-
expect(JSON.stringify(schema.properties.flag)).toMatch(/0|1/);
|
|
256
|
-
expect(schema.properties.flag).not.toEqual({});
|
|
257
|
-
});
|
|
258
|
-
test('harvests nested objects through generated auth/schema and alias imports', async () => {
|
|
259
|
-
const action = `
|
|
260
|
-
import { z } from 'zod';
|
|
261
|
-
import { defineAction } from '../.quickback/define-action';
|
|
262
|
-
import { user } from '../../../auth/schema';
|
|
263
|
-
import { ActionError } from '~/lib/types';
|
|
264
|
-
export default defineAction({
|
|
265
|
-
input: z.object({
|
|
266
|
-
organization: z.object({ name: z.string(), slug: z.string() }),
|
|
267
|
-
owner: z.object({ name: z.string(), email: z.string().email() }),
|
|
268
|
-
event: z.object({ name: z.string(), slug: z.string(), startsAt: z.string(), endsAt: z.string() }).optional(),
|
|
269
|
-
}),
|
|
270
|
-
execute: async () => { void user; void ActionError; },
|
|
271
|
-
});
|
|
272
|
-
`;
|
|
273
|
-
const { projectRoot, featuresDir } = await stageProject({ 'onboarding/actions/createAccount.ts': action });
|
|
274
|
-
const schemas = await harvestActionInputSchemas({
|
|
275
|
-
projectRoot,
|
|
276
|
-
featuresDir,
|
|
277
|
-
features: [{ name: 'onboarding', actionFiles: { 'actions/createAccount.ts': '' } }],
|
|
278
|
-
});
|
|
279
|
-
const schema = schemas['src/features/onboarding/actions/createAccount.ts'];
|
|
280
|
-
expect(schema).toBeDefined();
|
|
281
|
-
expect(schema.type).toBe('object');
|
|
282
|
-
expect(schema.properties.organization.type).toBe('object');
|
|
283
|
-
expect(schema.properties.organization.properties.name.type).toBe('string');
|
|
284
|
-
expect(schema.properties.organization.properties.slug.type).toBe('string');
|
|
285
|
-
expect(schema.properties.owner.type).toBe('object');
|
|
286
|
-
expect(schema.properties.owner.properties.email.format).toBe('email');
|
|
287
|
-
expect(schema.properties.event.type).toBe('object');
|
|
288
|
-
expect(schema.properties.name).toBeUndefined();
|
|
289
|
-
expect(schema.properties.slug).toBeUndefined();
|
|
290
|
-
expect(schema.properties.email).toBeUndefined();
|
|
291
|
-
});
|
|
292
|
-
test('ActionError/TransitionLostError import from the define-action helper (its documented re-export)', async () => {
|
|
293
|
-
const action = `
|
|
294
|
-
import { z } from 'zod';
|
|
295
|
-
import { defineAction, ActionError, TransitionLostError } from '../.quickback/define-action';
|
|
296
|
-
export default defineAction({
|
|
297
|
-
input: z.object({ name: z.string() }),
|
|
298
|
-
execute: async () => { void ActionError; void TransitionLostError; },
|
|
299
|
-
});
|
|
300
|
-
`;
|
|
301
|
-
const { projectRoot, featuresDir } = await stageProject({ 'agenda/actions/renameGroup.ts': action });
|
|
302
|
-
const schemas = await harvestActionInputSchemas({
|
|
303
|
-
projectRoot,
|
|
304
|
-
featuresDir,
|
|
305
|
-
features: [{ name: 'agenda', actionFiles: { 'actions/renameGroup.ts': '' } }],
|
|
306
|
-
});
|
|
307
|
-
const schema = schemas['src/features/agenda/actions/renameGroup.ts'];
|
|
308
|
-
expect(schema).toBeDefined();
|
|
309
|
-
expect(schema.properties.name.type).toBe('string');
|
|
310
|
-
});
|
|
311
|
-
// Regression: the emitted define-action helper also re-exports the feature's
|
|
312
|
-
// TABLE for typing, and the documented authoring style imports it —
|
|
313
|
-
// `import { defineAction, applications } from '../.quickback/define-action'`.
|
|
314
|
-
// The old fixed-name ESM stub declared only defineAction/default/ActionError/
|
|
315
|
-
// TransitionLostError, so any table import was an esbuild bundle-time hard
|
|
316
|
-
// failure (the deterministic 9/18 partial harvest on examples/recruitment).
|
|
317
|
-
test('table names imported alongside defineAction (documented style) still harvest', async () => {
|
|
318
|
-
const action = `
|
|
319
|
-
import { z } from 'zod';
|
|
320
|
-
import { defineAction, applications } from '../.quickback/define-action';
|
|
321
|
-
export default defineAction({
|
|
322
|
-
input: z.object({ note: z.string().min(1) }),
|
|
323
|
-
execute: async ({ db }) => { void db.update(applications); },
|
|
324
|
-
});
|
|
325
|
-
`;
|
|
326
|
-
const { projectRoot, featuresDir } = await stageProject({ 'applications/actions/advance.ts': action });
|
|
327
|
-
const result = await harvestActionInputSchemasDetailed({
|
|
328
|
-
projectRoot,
|
|
329
|
-
featuresDir,
|
|
330
|
-
features: [{ name: 'applications', actionFiles: { 'actions/advance.ts': '' } }],
|
|
331
|
-
});
|
|
332
|
-
expect(result.diagnostics).toEqual([]);
|
|
333
|
-
const schema = result.schemas['src/features/applications/actions/advance.ts'];
|
|
334
|
-
expect(schema).toBeDefined();
|
|
335
|
-
expect(schema.properties.note.minLength).toBe(1);
|
|
336
|
-
});
|
|
337
|
-
test('real ~/lib imports still bundle when they define input schemas', async () => {
|
|
338
|
-
const action = `
|
|
339
|
-
import { nestedInput } from '~/lib/inputs';
|
|
340
|
-
export default { input: nestedInput };
|
|
341
|
-
`;
|
|
342
|
-
const { projectRoot, featuresDir } = await stageProject({ 'accounts/actions/createAccount.ts': action });
|
|
343
|
-
await mkdir(join(projectRoot, 'lib'), { recursive: true });
|
|
344
|
-
await writeFile(join(projectRoot, 'lib', 'inputs.ts'), `
|
|
345
|
-
import { z } from 'zod';
|
|
346
|
-
export const nestedInput = z.object({
|
|
347
|
-
profile: z.object({ displayName: z.string(), email: z.string().email() }),
|
|
348
|
-
});
|
|
349
|
-
`, 'utf-8');
|
|
350
|
-
const schemas = await harvestActionInputSchemas({
|
|
351
|
-
projectRoot,
|
|
352
|
-
featuresDir,
|
|
353
|
-
features: [{ name: 'accounts', actionFiles: { 'actions/createAccount.ts': '' } }],
|
|
354
|
-
});
|
|
355
|
-
const schema = schemas['src/features/accounts/actions/createAccount.ts'];
|
|
356
|
-
expect(schema).toBeDefined();
|
|
357
|
-
expect(schema.properties.profile.type).toBe('object');
|
|
358
|
-
expect(schema.properties.profile.properties.displayName.type).toBe('string');
|
|
359
|
-
expect(schema.properties.profile.properties.email.format).toBe('email');
|
|
360
|
-
});
|
|
361
|
-
test.skipIf(!HAS_REPO_ROOT_DEPS)('Attend-shaped actions resolve dependencies installed only under nested build.outputDir', async () => {
|
|
362
|
-
// Keep this project outside the Quickback checkout so ordinary upward
|
|
363
|
-
// node_modules discovery cannot accidentally make the regression pass.
|
|
364
|
-
const sandboxRoot = join(tmpdir(), `qb-attend-output-${randomUUID().slice(0, 8)}`);
|
|
365
|
-
const projectRoot = join(sandboxRoot, 'backend-v2');
|
|
366
|
-
stagedDirs.push(sandboxRoot);
|
|
367
|
-
const featuresDir = join(projectRoot, 'quickback', 'features');
|
|
368
|
-
const runtimeDir = join(projectRoot, 'src');
|
|
369
|
-
const actionPath = join(featuresDir, 'events', 'actions', 'createEvent.ts');
|
|
370
|
-
await mkdir(join(actionPath, '..'), { recursive: true });
|
|
371
|
-
await mkdir(join(featuresDir, 'events', 'lib'), { recursive: true });
|
|
372
|
-
await mkdir(join(featuresDir, 'command_idempotency'), { recursive: true });
|
|
373
|
-
await mkdir(join(featuresDir, 'events'), { recursive: true });
|
|
374
|
-
await mkdir(join(runtimeDir, 'node_modules'), { recursive: true });
|
|
375
|
-
await symlink(REPO_ZOD, join(runtimeDir, 'node_modules', 'zod'), 'dir');
|
|
376
|
-
await symlink(REPO_DRIZZLE, join(runtimeDir, 'node_modules', 'drizzle-orm'), 'dir');
|
|
377
|
-
// Model an unrelated ancestor install. `nodePaths` alone is fallback-only
|
|
378
|
-
// and would incorrectly select this package before the generated runtime's
|
|
379
|
-
// dependency root, reproducing the real Attend worktree failure.
|
|
380
|
-
await mkdir(join(sandboxRoot, 'node_modules', 'zod'), { recursive: true });
|
|
381
|
-
await writeFile(join(sandboxRoot, 'node_modules', 'zod', 'package.json'), JSON.stringify({
|
|
382
|
-
name: 'zod',
|
|
383
|
-
version: '3.0.0-test',
|
|
384
|
-
type: 'module',
|
|
385
|
-
exports: './index.js',
|
|
386
|
-
}), 'utf-8');
|
|
387
|
-
await writeFile(join(sandboxRoot, 'node_modules', 'zod', 'index.js'), `export const z = {};`, 'utf-8');
|
|
388
|
-
await writeFile(join(featuresDir, 'events', 'events.ts'), `
|
|
389
|
-
import { feature, q } from '@quickback/compiler';
|
|
390
|
-
export const events = feature('events', q.table({ id: q.id() }));
|
|
391
|
-
`, 'utf-8');
|
|
392
|
-
await writeFile(join(featuresDir, 'command_idempotency', 'command_idempotency.ts'), `
|
|
393
|
-
import { feature, q } from '@quickback/compiler';
|
|
394
|
-
export const command_idempotency = feature('command_idempotency', q.table({ id: q.id() }));
|
|
395
|
-
`, 'utf-8');
|
|
396
|
-
await writeFile(join(featuresDir, 'events', 'lib', 'create-event-input.ts'), `
|
|
397
|
-
import { z } from 'zod';
|
|
398
|
-
import { command_idempotency } from '../../command_idempotency/command_idempotency';
|
|
399
|
-
import { events } from '../events';
|
|
400
|
-
|
|
401
|
-
// Attend inventory DTOs build projections at module load. The harvester must
|
|
402
|
-
// keep this inert table-column access from blocking the reusable input schema.
|
|
403
|
-
export const eventProjection = {
|
|
404
|
-
eventId: events.id,
|
|
405
|
-
commandId: command_idempotency.id,
|
|
406
|
-
};
|
|
407
|
-
export const localDateTime = z.string().regex(
|
|
408
|
-
/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2})?$/,
|
|
409
|
-
'Expected a local ISO date-time without an offset',
|
|
410
|
-
);
|
|
411
|
-
`, 'utf-8');
|
|
412
|
-
await writeFile(actionPath, `
|
|
413
|
-
import { and, eq } from 'drizzle-orm';
|
|
414
|
-
import { z } from 'zod';
|
|
415
|
-
import { ActionError } from '@quickback/compiler';
|
|
416
|
-
import { defineAction } from '../.quickback/define-action';
|
|
417
|
-
import { command_idempotency } from '../../command_idempotency/command_idempotency';
|
|
418
|
-
import { events } from '../events';
|
|
419
|
-
import { eventProjection, localDateTime } from '../lib/create-event-input';
|
|
420
|
-
|
|
421
|
-
export default defineAction({
|
|
422
|
-
path: '/organizations/:organizationId/events',
|
|
423
|
-
method: 'POST',
|
|
424
|
-
input: z.object({
|
|
425
|
-
idempotencyKey: z.string().min(8).max(200),
|
|
426
|
-
name: z.string().trim().min(1).max(200),
|
|
427
|
-
startsAt: localDateTime,
|
|
428
|
-
endsAt: localDateTime,
|
|
429
|
-
}),
|
|
430
|
-
execute: async () => { void and; void eq; void ActionError; void command_idempotency; void events; void eventProjection; },
|
|
431
|
-
});
|
|
432
|
-
`, 'utf-8');
|
|
433
|
-
await writeFile(join(featuresDir, 'events/actions/getBundle.ts'), `
|
|
434
|
-
import { defineBundle, list } from '../.quickback/define-bundle';
|
|
435
|
-
export default defineBundle({
|
|
436
|
-
description: 'Events bundle', path: '/bundle', access: { roles: ['member'] },
|
|
437
|
-
sections: { events: list('events') },
|
|
438
|
-
});
|
|
439
|
-
`, 'utf-8');
|
|
440
|
-
const result = await harvestActionInputSchemasDetailed({
|
|
441
|
-
projectRoot,
|
|
442
|
-
featuresDir,
|
|
443
|
-
dependencyRoots: [join(runtimeDir, 'node_modules')],
|
|
444
|
-
features: [{ name: 'events', actionFiles: { 'actions/createEvent.ts': '', 'actions/getBundle.ts': '' } }],
|
|
445
|
-
});
|
|
446
|
-
const key = 'src/features/events/actions/createEvent.ts';
|
|
447
|
-
const schema = result.schemas[key];
|
|
448
|
-
expect(result.diagnostics).toEqual([]);
|
|
449
|
-
expect(schema.properties.idempotencyKey.minLength).toBe(8);
|
|
450
|
-
expect(schema.properties.name.maxLength).toBe(200);
|
|
451
|
-
expect(schema.properties.startsAt.pattern).toContain('\\d{4}');
|
|
452
|
-
const bundle = result.schemas['src/features/events/actions/getBundle.ts'];
|
|
453
|
-
expect(bundle.properties.sections).toEqual({ type: 'array', items: { type: 'string' } });
|
|
454
|
-
expect(bundle.properties.ifNoneMatch).toEqual({ type: 'string' });
|
|
455
|
-
});
|
|
456
|
-
test('returns the exact action and bundle reason when a dependency cannot resolve', async () => {
|
|
457
|
-
const action = `
|
|
458
|
-
import { schema } from 'attend-missing-action-schema-package';
|
|
459
|
-
export default { input: schema };
|
|
460
|
-
`;
|
|
461
|
-
const { projectRoot, featuresDir } = await stageProject({ 'events/actions/broken.ts': action });
|
|
462
|
-
const result = await harvestActionInputSchemasDetailed({
|
|
463
|
-
projectRoot,
|
|
464
|
-
featuresDir,
|
|
465
|
-
features: [{ name: 'events', actionFiles: { 'actions/broken.ts': '' } }],
|
|
466
|
-
});
|
|
467
|
-
expect(result.schemas).toEqual({});
|
|
468
|
-
expect(result.diagnostics).toHaveLength(1);
|
|
469
|
-
expect(result.diagnostics[0]?.key).toBe('src/features/events/actions/broken.ts');
|
|
470
|
-
expect(result.diagnostics[0]?.phase).toBe('bundle');
|
|
471
|
-
expect(result.diagnostics[0]?.message).toContain('attend-missing-action-schema-package');
|
|
472
|
-
});
|
|
473
|
-
});
|
|
474
|
-
// ── Regression: feature-area source paths (v2 harvest) ──────────────────────
|
|
475
|
-
// The v2 action harvest reconstructs an on-disk source path per action. It must
|
|
476
|
-
// follow the AUTHORED directory (area-aware `sourceDir`), not the flat global
|
|
477
|
-
// leaf `name` — otherwise nested-area actions resolve to a directory that does
|
|
478
|
-
// not contain the file and their bare/feature-local imports fail to resolve.
|
|
479
|
-
describe('action harvest — feature-area source paths', () => {
|
|
480
|
-
const AREA_TS = `import { defineArea } from '@quickback/compiler';
|
|
481
|
-
export default defineArea({ name: 'eventScope', prefix: '/event/:eventId' });
|
|
482
|
-
`;
|
|
483
|
-
const action = (field) => `import { defineAction } from '../.quickback/define-action';
|
|
484
|
-
import { z } from 'zod';
|
|
485
|
-
export default defineAction({ input: z.object({ ${field}: z.string().min(1) }) });
|
|
486
|
-
`;
|
|
487
|
-
test('all three shapes resolve to their authored file; staging key stays the global leaf', async () => {
|
|
488
|
-
// Shapes staged at their REAL authored paths:
|
|
489
|
-
// 1. flat feature todos/
|
|
490
|
-
// 2. area folder = a feature events/ (name events, sourceDir events)
|
|
491
|
-
// 3. leaf nested under area events/conversations/
|
|
492
|
-
const { projectRoot, featuresDir } = await stageProject({
|
|
493
|
-
'todos/actions/addTodo.ts': action('title'),
|
|
494
|
-
'events/actions/updateEvent.ts': action('name'),
|
|
495
|
-
'events/conversations/actions/postMessage.ts': action('body'),
|
|
496
|
-
});
|
|
497
|
-
// Features exactly as the file loader produces them (name = global leaf,
|
|
498
|
-
// sourceDir = authored dir). Note: area-as-feature sourceDir is `events`,
|
|
499
|
-
// NEVER `events/events`.
|
|
500
|
-
const features = [
|
|
501
|
-
{ name: 'todos', sourceDir: 'todos', actionFiles: { 'actions/addTodo.ts': '' } },
|
|
502
|
-
{ name: 'events', sourceDir: 'events', actionFiles: { 'actions/updateEvent.ts': '' } },
|
|
503
|
-
{ name: 'conversations', sourceDir: 'events/conversations', actionFiles: { 'actions/postMessage.ts': '' } },
|
|
504
|
-
];
|
|
505
|
-
const result = await harvestActionInputSchemasDetailed({ projectRoot, featuresDir, features });
|
|
506
|
-
// Every action resolved — no missing keys (fail-closed v2 gate is satisfied).
|
|
507
|
-
expect(missingActionInputSchemaKeys(features, result.schemas)).toEqual([]);
|
|
508
|
-
expect(result.diagnostics).toEqual([]);
|
|
509
|
-
// Staging keys are the GLOBAL LEAF identity (area-independent) — the bundle
|
|
510
|
-
// read the exact authored file, and bare `zod` resolved from it.
|
|
511
|
-
expect(result.schemas['src/features/todos/actions/addTodo.ts']).toBeDefined();
|
|
512
|
-
expect(result.schemas['src/features/events/actions/updateEvent.ts']).toBeDefined();
|
|
513
|
-
expect(result.schemas['src/features/conversations/actions/postMessage.ts']?.properties?.body).toBeDefined();
|
|
514
|
-
});
|
|
515
|
-
test('REGRESSION GUARD: dropping sourceDir (flat reconstruction) fails the nested-area action', async () => {
|
|
516
|
-
const { projectRoot, featuresDir } = await stageProject({
|
|
517
|
-
'events/conversations/actions/postMessage.ts': action('body'),
|
|
518
|
-
});
|
|
519
|
-
// Simulate the pre-fix compile.ts mapping that passed only { name, actionFiles }.
|
|
520
|
-
const flat = [
|
|
521
|
-
{ name: 'conversations', actionFiles: { 'actions/postMessage.ts': '' } },
|
|
522
|
-
];
|
|
523
|
-
const result = await harvestActionInputSchemasDetailed({ projectRoot, featuresDir, features: flat });
|
|
524
|
-
// Without sourceDir the harvest looks under features/conversations/ (wrong) —
|
|
525
|
-
// the action is not found there, so the v2 completeness gate reports it.
|
|
526
|
-
expect(missingActionInputSchemaKeys(flat, result.schemas)).toEqual([
|
|
527
|
-
'src/features/conversations/actions/postMessage.ts',
|
|
528
|
-
]);
|
|
529
|
-
});
|
|
530
|
-
test('a genuinely broken nested action still produces its own bounded diagnostic', async () => {
|
|
531
|
-
const { projectRoot, featuresDir } = await stageProject({
|
|
532
|
-
'events/conversations/actions/good.ts': action('body'),
|
|
533
|
-
'events/conversations/actions/broken.ts': `import { z } from 'zod';\nexport default { input: z.object({ x: z.string() }) // missing paren\n`,
|
|
534
|
-
});
|
|
535
|
-
const features = [
|
|
536
|
-
{ name: 'conversations', sourceDir: 'events/conversations', actionFiles: { 'actions/good.ts': '', 'actions/broken.ts': '' } },
|
|
537
|
-
];
|
|
538
|
-
const result = await harvestActionInputSchemasDetailed({ projectRoot, featuresDir, features });
|
|
539
|
-
// The good one resolves; only the broken one is diagnosed, keyed by its
|
|
540
|
-
// global-leaf staging path — a bounded, per-action failure.
|
|
541
|
-
expect(result.schemas['src/features/conversations/actions/good.ts']).toBeDefined();
|
|
542
|
-
expect(result.diagnostics.map((d) => d.key)).toEqual(['src/features/conversations/actions/broken.ts']);
|
|
543
|
-
});
|
|
544
|
-
test('END-TO-END: real loadFeatures → compile.ts mapping → harvest resolves every action', async () => {
|
|
545
|
-
// Guards against a hand-built flat input giving false confidence: this drives
|
|
546
|
-
// the ACTUAL loader and the EXACT compile.ts feature-mapping expression.
|
|
547
|
-
const { projectRoot, featuresDir } = await stageProject({
|
|
548
|
-
'events/_area.ts': AREA_TS,
|
|
549
|
-
'events/actions/updateEvent.ts': action('name'),
|
|
550
|
-
'events/conversations/actions/postMessage.ts': action('body'),
|
|
551
|
-
'todos/actions/addTodo.ts': action('title'),
|
|
552
|
-
});
|
|
553
|
-
const { features: loaded } = await loadFeatures(featuresDir);
|
|
554
|
-
// The exact mapping compile.ts uses to build the harvest input.
|
|
555
|
-
const harvestFeatures = loaded.map((f) => ({
|
|
556
|
-
name: f.name,
|
|
557
|
-
sourceDir: f.sourceDir,
|
|
558
|
-
actionFiles: f.actionFiles,
|
|
559
|
-
}));
|
|
560
|
-
const result = await harvestActionInputSchemasDetailed({ projectRoot, featuresDir, features: harvestFeatures });
|
|
561
|
-
expect(missingActionInputSchemaKeys(harvestFeatures, result.schemas)).toEqual([]);
|
|
562
|
-
expect(result.schemas['src/features/conversations/actions/postMessage.ts']).toBeDefined();
|
|
563
|
-
expect(result.schemas['src/features/events/actions/updateEvent.ts']).toBeDefined();
|
|
564
|
-
expect(result.schemas['src/features/todos/actions/addTodo.ts']).toBeDefined();
|
|
565
|
-
});
|
|
566
|
-
// ── The Failure-A matrix: a nested action whose INPUT schema depends on Zod
|
|
567
|
-
// VALUES imported from other features. Pre-fix, the flat/global import
|
|
568
|
-
// (`../../events/lib/...`) under-resolved by the area depth, the harvest
|
|
569
|
-
// stubbed the module, and `z.toJSONSchema` threw on the undefined value
|
|
570
|
-
// ("Cannot read properties of undefined (reading '_zod')"). The
|
|
571
|
-
// feature-directory index re-resolves these depth-independently.
|
|
572
|
-
test('nested action input resolves cross-feature Zod VALUES (area-root, flat-support, sibling, feature-local)', async () => {
|
|
573
|
-
const zmod = (body) => `import { z } from 'zod';\n${body}\n`;
|
|
574
|
-
const { projectRoot, featuresDir } = await stageProject({
|
|
575
|
-
// area root (its own feature) + a shared Zod contract in its lib/
|
|
576
|
-
'events/_area.ts': AREA_TS,
|
|
577
|
-
'events/lib/contracts.ts': zmod(`export const eventRef = z.object({ eventId: z.string().uuid() });`),
|
|
578
|
-
// sibling leaf under the SAME area (resolves physically — control edge)
|
|
579
|
-
'events/badges/lib/badge-contract.ts': zmod(`export const badgeRef = z.object({ badgeId: z.string() });`),
|
|
580
|
-
// flat SUPPORT feature OUTSIDE the area (cross-depth — index-only)
|
|
581
|
-
'shared/lib/common.ts': zmod(`export const sharedRef = z.object({ tag: z.string() });`),
|
|
582
|
-
// the nested leaf: feature-local lib (physical) + the action itself
|
|
583
|
-
'events/activities/lib/schedule.ts': zmod(`export const scheduleField = z.string().min(1);`),
|
|
584
|
-
'events/activities/actions/createActivity.ts': `import { defineAction } from '../.quickback/define-action';
|
|
585
|
-
import { z } from 'zod';
|
|
586
|
-
import { eventRef } from '../../events/lib/contracts';
|
|
587
|
-
import { badgeRef } from '../../badges/lib/badge-contract';
|
|
588
|
-
import { sharedRef } from '../../shared/lib/common';
|
|
589
|
-
import { scheduleField } from '../lib/schedule';
|
|
590
|
-
export default defineAction({
|
|
591
|
-
input: z.object({ event: eventRef, badge: badgeRef, shared: sharedRef, when: scheduleField }),
|
|
592
|
-
});
|
|
593
|
-
`,
|
|
594
|
-
});
|
|
595
|
-
// Every feature is in the index (even action-less ones) so cross-feature
|
|
596
|
-
// imports can resolve to a lib-only feature.
|
|
597
|
-
const features = [
|
|
598
|
-
{ name: 'events', sourceDir: 'events', actionFiles: {} },
|
|
599
|
-
{ name: 'badges', sourceDir: 'events/badges', actionFiles: {} },
|
|
600
|
-
{ name: 'shared', sourceDir: 'shared', actionFiles: {} },
|
|
601
|
-
{ name: 'activities', sourceDir: 'events/activities', actionFiles: { 'actions/createActivity.ts': '' } },
|
|
602
|
-
];
|
|
603
|
-
const result = await harvestActionInputSchemasDetailed({ projectRoot, featuresDir, features });
|
|
604
|
-
// Fail-closed v2 gate satisfied and no per-action diagnostics — every
|
|
605
|
-
// imported Zod value was the REAL schema, not an inert stub.
|
|
606
|
-
expect(result.diagnostics).toEqual([]);
|
|
607
|
-
expect(missingActionInputSchemaKeys(features, result.schemas)).toEqual([]);
|
|
608
|
-
const schema = result.schemas['src/features/activities/actions/createActivity.ts'];
|
|
609
|
-
// Each imported value contributed its shape — proof the module resolved.
|
|
610
|
-
expect(schema?.properties?.event?.properties?.eventId).toBeDefined(); // area-root lib
|
|
611
|
-
expect(schema?.properties?.badge?.properties?.badgeId).toBeDefined(); // sibling lib
|
|
612
|
-
expect(schema?.properties?.shared?.properties?.tag).toBeDefined(); // flat-support lib
|
|
613
|
-
expect(schema?.properties?.when).toBeDefined(); // feature-local lib
|
|
614
|
-
});
|
|
615
|
-
// Depth guard: a FEATURE-LOCAL import that misses on disk must stay
|
|
616
|
-
// fail-closed even when its leading segment collides with a sibling feature
|
|
617
|
-
// NAME — the index must not silently swap in the foreign feature's module.
|
|
618
|
-
test('feature-local miss does NOT resolve to a same-named sibling feature (stays fail-closed)', async () => {
|
|
619
|
-
const zmod = (body) => `import { z } from 'zod';\n${body}\n`;
|
|
620
|
-
const { projectRoot, featuresDir } = await stageProject({
|
|
621
|
-
// A real sibling feature literally named `shared` with a real lib file.
|
|
622
|
-
'shared/lib/x.ts': zmod(`export const foreignRef = z.object({ FOREIGN: z.string() });`),
|
|
623
|
-
// The action intends a FEATURE-LOCAL `../shared/lib/x` (one `..`, under its
|
|
624
|
-
// OWN feature dir `events/activities/`), which does NOT exist on disk.
|
|
625
|
-
'events/activities/actions/createActivity.ts': `import { defineAction } from '../.quickback/define-action';
|
|
626
|
-
import { z } from 'zod';
|
|
627
|
-
import { foreignRef } from '../shared/lib/x';
|
|
628
|
-
export default defineAction({ input: z.object({ x: foreignRef }) });
|
|
629
|
-
`,
|
|
630
|
-
});
|
|
631
|
-
const features = [
|
|
632
|
-
{ name: 'shared', sourceDir: 'shared', actionFiles: {} },
|
|
633
|
-
{ name: 'activities', sourceDir: 'events/activities', actionFiles: { 'actions/createActivity.ts': '' } },
|
|
634
|
-
];
|
|
635
|
-
const result = await harvestActionInputSchemasDetailed({ projectRoot, featuresDir, features });
|
|
636
|
-
// Fail-CLOSED: the missing feature-local import is not silently redirected to
|
|
637
|
-
// features/shared/lib/x — the action is reported, not given a foreign schema.
|
|
638
|
-
expect(missingActionInputSchemaKeys(features, result.schemas)).toEqual([
|
|
639
|
-
'src/features/activities/actions/createActivity.ts',
|
|
640
|
-
]);
|
|
641
|
-
const schema = result.schemas['src/features/activities/actions/createActivity.ts'];
|
|
642
|
-
expect(schema?.properties?.x?.properties?.FOREIGN).toBeUndefined();
|
|
643
|
-
});
|
|
644
|
-
});
|
|
645
|
-
//# sourceMappingURL=action-harvest.test.js.map
|