|
| 1 | +// Copyright (c) 2026 ObjectStack contributors. Apache-2.0 license. |
| 2 | +// |
| 3 | +// A change saved in Studio to an item the app ships is an item of the app's |
| 4 | +// paired `.custom` package, stored in the environment's database (ADR-0146 |
| 5 | +// D2) — never in `src/`, so `build` and the Dockerfile leave it behind. The |
| 6 | +// scaffold's two docs a developer and their coding agent read first must say |
| 7 | +// so, name the command that takes it out (`os package export`), and tell the |
| 8 | +// agent to make app changes in `src/`. Both are static files `index.ts` |
| 9 | +// copies, so a source-text pin is what covers them. |
| 10 | + |
| 11 | +import { describe, it, expect } from 'vitest'; |
| 12 | +import fs from 'node:fs'; |
| 13 | +import path from 'node:path'; |
| 14 | +import { fileURLToPath } from 'node:url'; |
| 15 | + |
| 16 | +const templatesDir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'templates'); |
| 17 | +const AGENTS_MD = fs.readFileSync(path.join(templatesDir, 'AGENTS.md'), 'utf8'); |
| 18 | +const README = fs.readFileSync(path.join(templatesDir, 'blank', 'README.md'), 'utf8'); |
| 19 | + |
| 20 | +/** The section under the heading that matches `heading`, up to the next heading of that level or higher. */ |
| 21 | +function section(markdown: string, heading: RegExp, level: number): string { |
| 22 | + const lines = markdown.split('\n'); |
| 23 | + const at = lines.findIndex((l) => heading.test(l)); |
| 24 | + if (at === -1) return ''; |
| 25 | + const stop = new RegExp(`^#{1,${level}} `); |
| 26 | + const end = lines.findIndex((l, i) => i > at && stop.test(l)); |
| 27 | + return lines.slice(at, end === -1 ? undefined : end).join('\n'); |
| 28 | +} |
| 29 | + |
| 30 | +describe.each([ |
| 31 | + ['the scaffold AGENTS.md', section(AGENTS_MD, /^## .*Studio/, 2)], |
| 32 | + ['the blank README', section(README, /^### .*Studio/, 3)], |
| 33 | +])('%s says a Studio change does not travel with the build', (_doc, text) => { |
| 34 | + it('has the section (vacuity guard)', () => { |
| 35 | + expect(text.length).toBeGreaterThan(200); |
| 36 | + }); |
| 37 | + |
| 38 | + it('says where the change lives and that the build leaves it behind', () => { |
| 39 | + expect(text).toContain('.custom'); |
| 40 | + expect(text).toMatch(/database/); |
| 41 | + expect(text).toContain('src/'); |
| 42 | + expect(text).toContain('Dockerfile'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('names the command that takes it out, and the install on the target', () => { |
| 46 | + expect(text).toContain('os package export'); |
| 47 | + expect(text).toContain('os package install'); |
| 48 | + }); |
| 49 | +}); |
| 50 | + |
| 51 | +describe('the scaffold AGENTS.md tells the agent where app changes go', () => { |
| 52 | + it('makes app changes in src/, not through Studio', () => { |
| 53 | + const text = section(AGENTS_MD, /^## .*Studio/, 2); |
| 54 | + expect(text).toMatch(/\*\*Make every change to the app in `src\/`\*\*, never through Studio/); |
| 55 | + }); |
| 56 | +}); |
0 commit comments