-
Notifications
You must be signed in to change notification settings - Fork 0
Add README scaffolding to create wizard: default-on toggle, seeded template, authored-content preservation, and atomic write transaction #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ export const createCommand: Command = { | |
| skill: { type: 'array', description: 'Skill to scaffold, repeatable (headless mode)' }, | ||
| agent: { type: 'array', description: 'Agent to scaffold, repeatable (headless mode)' }, | ||
| command: { type: 'array', description: 'Command to scaffold, repeatable (headless mode)' }, | ||
| readme: { type: 'boolean', description: 'Scaffold a README.md (default on; pass --no-readme to skip)' }, | ||
|
cursor[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When users run Useful? React with 👍 / 👎. |
||
| json: { type: 'boolean', description: 'Emit machine-readable JSON to stdout (headless mode)' }, | ||
| }, | ||
| run: async (args: string[], flags: Record<string, unknown>): Promise<number> => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { describe, expect, test } from 'bun:test' | ||
| import type { ScaffoldReadme } from '@agent-facets/engine' | ||
| import { render } from 'ink-testing-library' | ||
| import { useEffect } from 'react' | ||
| import { FormStateProvider, useFormState } from '../form-state-context.ts' | ||
|
|
||
| /** | ||
| * Drives a sequence of form mutations on mount, then reports the narrowed | ||
| * `toCreateOptions().readme` on every render so assertions observe the settled | ||
| * state after React flushes updates. | ||
| */ | ||
| function Probe({ | ||
| steps, | ||
| report, | ||
| }: { | ||
| steps: (ctx: ReturnType<typeof useFormState>) => void | ||
| report: (r: ScaffoldReadme) => void | ||
| }) { | ||
| const ctx = useFormState() | ||
| useEffect(() => { | ||
| steps(ctx) | ||
| }, [steps, ctx]) | ||
| report(ctx.toCreateOptions().readme) | ||
| return null | ||
|
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For each test whose Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| function nextTick(): Promise<void> { | ||
| return new Promise((resolve) => setImmediate(resolve)) | ||
| } | ||
|
|
||
| async function run(steps: (ctx: ReturnType<typeof useFormState>) => void): Promise<ScaffoldReadme> { | ||
| let result: ScaffoldReadme = { kind: 'disabled' } | ||
| const instance = render( | ||
| <FormStateProvider> | ||
| <Probe steps={steps} report={(r) => (result = r)} /> | ||
| </FormStateProvider>, | ||
| ) | ||
| await nextTick() | ||
| instance.unmount() | ||
| return result | ||
| } | ||
|
|
||
| describe('create README form state', () => { | ||
| test('README is enabled by default', async () => { | ||
| const readme = await run(() => {}) | ||
| expect(readme.kind).toBe('enabled') | ||
| }) | ||
|
|
||
| test('seeded content re-seeds from identity edits', async () => { | ||
| const readme = await run((ctx) => { | ||
| ctx.setFieldValue('name', 'my-facet') | ||
| ctx.setFieldValue('description', 'Neat tools') | ||
| }) | ||
| if (readme.kind !== 'enabled') expect.unreachable() | ||
| expect(readme.content).toBe('# my-facet\n\nNeat tools\n') | ||
| }) | ||
|
|
||
| test('authored content is preserved across later identity edits', async () => { | ||
| const readme = await run((ctx) => { | ||
| ctx.setFieldValue('name', 'my-facet') | ||
| ctx.setReadmeContent('# Custom\n\nHand-written docs.\n') | ||
| // A later identity edit MUST NOT regenerate the authored content. | ||
| ctx.setFieldValue('name', 'renamed') | ||
| }) | ||
| if (readme.kind !== 'enabled') expect.unreachable() | ||
| expect(readme.content).toBe('# Custom\n\nHand-written docs.\n') | ||
| }) | ||
|
|
||
| test('disable then re-enable preserves the draft', async () => { | ||
| const readme = await run((ctx) => { | ||
| ctx.setReadmeContent('# Kept\n') | ||
| ctx.setReadmeEnabled(false) | ||
| ctx.setReadmeEnabled(true) | ||
| }) | ||
| if (readme.kind !== 'enabled') expect.unreachable() | ||
| expect(readme.content).toBe('# Kept\n') | ||
| }) | ||
|
|
||
| test('disabled narrows to a disabled scaffold option', async () => { | ||
| const readme = await run((ctx) => { | ||
| ctx.setReadmeEnabled(false) | ||
| }) | ||
| expect(readme).toEqual({ kind: 'disabled' }) | ||
| }) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.