|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * PIN (#20333) — `npm create objectstack` → `os g flow` → `os validate` |
| 5 | + * counts the flow, with `os g object` as the control. |
| 6 | + * |
| 7 | + * ## What was measured before the fix |
| 8 | + * |
| 9 | + * On `origin/main` `c74de10a9`, a project scaffolded by the on-ramp's real |
| 10 | + * `bin/` entry, then `os g object order_line` and `os g flow order_line`: |
| 11 | + * |
| 12 | + * os g object exit 0, "Reaches the stack" (objects was always wired) |
| 13 | + * os g flow exit 0, "Not wired: … is not part of the stack" |
| 14 | + * os validate exit 0, `Data: 2 Objects` and `Logic: 0 Flows` |
| 15 | + * |
| 16 | + * The blank starter's config imported `./src/objects` alone, so the flow was |
| 17 | + * written and never loaded. The control is what makes the red readable: the |
| 18 | + * same chain counted the generated object, so a 0 for the flow is the wiring |
| 19 | + * and not a harness that counts nothing. |
| 20 | + * |
| 21 | + * ## The chain, through the real commands |
| 22 | + * |
| 23 | + * node create-objectstack/bin/create-objectstack.js my-app --skip-install --skip-skills |
| 24 | + * os g object order_line → exit 0, reaches the stack |
| 25 | + * os g flow order_line → exit 0, reaches the stack, no wiring lines to add |
| 26 | + * os validate → exit 0, `Data: 2 Objects`, `Logic: 1 Flows` |
| 27 | + * |
| 28 | + * Asserted: exit statuses, the named subjects, the absence of the wiring |
| 29 | + * lines `os g` prints for a scaffold that did not arrive (code an author |
| 30 | + * pastes), and the counts `os validate` prints. Prose is not pinned. The item |
| 31 | + * names are read off the generator roster, not written down. |
| 32 | + * |
| 33 | + * ## Why here, why a child process, and why this file is NOT named `.e2e` |
| 34 | + * |
| 35 | + * `os g` and `os validate` are this package's commands, and it already |
| 36 | + * depends on `create-objectstack`, so `@objectstack/cli#test`'s `^build` |
| 37 | + * builds the on-ramp's `dist/` — the tree its `bin/` copies from. The bin and |
| 38 | + * the blank template are declared cross-package inputs of this package |
| 39 | + * (scripts/cross-package-test-inputs.mjs, mirrored into turbo.json). |
| 40 | + * |
| 41 | + * The project lives under this package's `node_modules`, so the scaffolded |
| 42 | + * config's imports resolve to workspace copies without an install. Besides |
| 43 | + * `@objectstack/spec`, the blank config imports three connector packages; |
| 44 | + * they are this package's devDependencies for that reason alone, which is |
| 45 | + * also what puts them in this suite's build closure. |
| 46 | + * |
| 47 | + * An exit status is the contract, and `process.exit` inside a vitest worker |
| 48 | + * is not one, so the commands are spawned (the `integration` project). The |
| 49 | + * name keeps it in the per-PR run. The structural half — the blank config |
| 50 | + * wires exactly what `os init` wires — is `create-objectstack-wiring-parity.test.ts`. |
| 51 | + */ |
| 52 | + |
| 53 | +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; |
| 54 | +import { execFile } from 'node:child_process'; |
| 55 | +import { mkdtempSync, readFileSync, rmSync } from 'node:fs'; |
| 56 | +import { join, resolve } from 'node:path'; |
| 57 | +import { fileURLToPath } from 'node:url'; |
| 58 | +import { GENERATOR_SCAFFOLD_TARGETS } from '../src/commands/generate.js'; |
| 59 | +import { childEnv } from './helpers/serve-process.js'; |
| 60 | + |
| 61 | +const HERE = resolve(fileURLToPath(import.meta.url), '..'); |
| 62 | +const CLI = resolve(HERE, '../bin/run-dev.js'); |
| 63 | +const TSX = resolve(HERE, '../../../node_modules/.bin/tsx'); |
| 64 | + |
| 65 | +// One `resolve(HERE, …)` call per line: `check:cross-package-test-inputs` |
| 66 | +// reconstructs this read by SOURCE SCAN. |
| 67 | +const ON_RAMP_BIN = resolve(HERE, '../../..', 'packages/create-objectstack/bin/create-objectstack.js'); |
| 68 | + |
| 69 | +/** One plain-node scaffold, then three oclif + tsx cold starts, sequential. */ |
| 70 | +const RUN_TIMEOUT_MS = 240_000; |
| 71 | + |
| 72 | +const PROJECT = 'my-app'; |
| 73 | +const NS = 'my_app'; |
| 74 | +const STEM = 'order_line'; |
| 75 | + |
| 76 | +interface Run { |
| 77 | + code: number; |
| 78 | + stdout: string; |
| 79 | + stderr: string; |
| 80 | +} |
| 81 | + |
| 82 | +function run(file: string, args: string[], cwd: string): Promise<Run> { |
| 83 | + return new Promise((resolvePromise) => { |
| 84 | + execFile( |
| 85 | + file, |
| 86 | + args, |
| 87 | + { cwd, maxBuffer: 8 * 1024 * 1024, env: childEnv({ NO_COLOR: '1' }) }, |
| 88 | + (err, stdout, stderr) => { |
| 89 | + resolvePromise({ |
| 90 | + // `err.code` is the real exit status; a signalled child has none and |
| 91 | + // is reported as 1, never as 0. |
| 92 | + code: err |
| 93 | + ? typeof (err as { code?: unknown }).code === 'number' |
| 94 | + ? (err as unknown as { code: number }).code |
| 95 | + : 1 |
| 96 | + : 0, |
| 97 | + stdout: String(stdout), |
| 98 | + stderr: String(stderr), |
| 99 | + }); |
| 100 | + }, |
| 101 | + ); |
| 102 | + }); |
| 103 | +} |
| 104 | + |
| 105 | +const os = (args: string[], cwd: string) => run(TSX, [CLI, ...args], cwd); |
| 106 | +const out = (r: Run) => r.stdout + r.stderr; |
| 107 | + |
| 108 | +const target = (type: string) => { |
| 109 | + const t = GENERATOR_SCAFFOLD_TARGETS.find((g) => g.type === type); |
| 110 | + if (!t) throw new Error(`no '${type}' generator in the roster`); |
| 111 | + return t; |
| 112 | +}; |
| 113 | +const OBJECT = target('object'); |
| 114 | +const FLOW = target('flow'); |
| 115 | + |
| 116 | +let root: string; |
| 117 | +let project: string; |
| 118 | +let scaffold: Run; |
| 119 | +let genObject: Run; |
| 120 | +let genFlow: Run; |
| 121 | +let validate: Run; |
| 122 | + |
| 123 | +beforeAll(async () => { |
| 124 | + root = mkdtempSync(join(HERE, '..', 'node_modules', '.create-objectstack-reach-')); |
| 125 | + project = join(root, PROJECT); |
| 126 | + scaffold = await run(process.execPath, [ON_RAMP_BIN, PROJECT, '--skip-install', '--skip-skills'], root); |
| 127 | + // Sequential on purpose: the object first, so the flow binds to something |
| 128 | + // declared, and cold starts in a container several agents share. |
| 129 | + genObject = await os(['g', 'object', STEM], project); |
| 130 | + genFlow = await os(['g', 'flow', STEM], project); |
| 131 | + validate = await os(['validate'], project); |
| 132 | +}, RUN_TIMEOUT_MS); |
| 133 | + |
| 134 | +afterAll(() => { |
| 135 | + if (root) rmSync(root, { recursive: true, force: true }); |
| 136 | +}); |
| 137 | + |
| 138 | +describe('[#20333] `npm create objectstack` → `os g flow` → `os validate`', () => { |
| 139 | + it('the on-ramp scaffolded the project, under the namespace this file assumes', () => { |
| 140 | + expect(scaffold.code, out(scaffold)).toBe(0); |
| 141 | + expect(readFileSync(join(project, 'objectstack.config.ts'), 'utf-8')).toContain(`namespace: '${NS}'`); |
| 142 | + }); |
| 143 | + |
| 144 | + it('CONTROL: `os g object` reaches the stack', () => { |
| 145 | + expect(genObject.code, out(genObject)).toBe(0); |
| 146 | + expect(genObject.stdout).toContain(`'${OBJECT.itemName(STEM, NS)}'`); |
| 147 | + expect(genObject.stdout).not.toContain(`import * as ${OBJECT.stackKey}`); |
| 148 | + }); |
| 149 | + |
| 150 | + it('`os g flow` reaches the stack, with no wiring lines to add', () => { |
| 151 | + expect(genFlow.code, out(genFlow)).toBe(0); |
| 152 | + expect(genFlow.stdout).toContain(`'${FLOW.itemName(STEM, NS)}'`); |
| 153 | + expect(genFlow.stdout).not.toContain(`import * as ${FLOW.stackKey}`); |
| 154 | + // Nor a `requires` line: the starter already declares what a flow runs on. |
| 155 | + expect(genFlow.stdout).not.toContain('requires: ['); |
| 156 | + }); |
| 157 | + |
| 158 | + it('`os validate` exits 0 and counts the generated flow beside the control', () => { |
| 159 | + expect(validate.code, out(validate)).toBe(0); |
| 160 | + // The starter's own object plus the generated one. |
| 161 | + expect(validate.stdout).toMatch(/\bData: 2 Objects\b/); |
| 162 | + expect(validate.stdout).toMatch(/\bLogic: 1 Flows\b/); |
| 163 | + }); |
| 164 | +}); |
0 commit comments