|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { buildServerInstructions } from './build-server-instructions.ts'; |
| 3 | + |
| 4 | +describe('buildServerInstructions', () => { |
| 5 | + it('builds a coherent instruction set when all toolsets are enabled', () => { |
| 6 | + const instructions = buildServerInstructions({ |
| 7 | + devEnabled: true, |
| 8 | + testEnabled: true, |
| 9 | + docsEnabled: true, |
| 10 | + }); |
| 11 | + |
| 12 | + expect(instructions).toMatchInlineSnapshot(` |
| 13 | + "Follow these workflows when working with UI and/or Storybook. |
| 14 | +
|
| 15 | + ## UI Building and Story Writing Workflow |
| 16 | +
|
| 17 | + - Before creating or editing components or stories, call **get-storybook-story-instructions**. |
| 18 | + - Treat that tool's output as the source of truth for framework-specific imports, story patterns, and testing conventions. |
| 19 | + - After changing any component or story, call **preview-stories**. |
| 20 | + - Always include every returned preview URL in your user-facing response so the user can verify the visual result. |
| 21 | +
|
| 22 | + ## Validation Workflow |
| 23 | +
|
| 24 | + - After each component or story change, run **run-story-tests**. |
| 25 | + - Use focused runs while iterating, then run a broad pass before final handoff when scope is unclear or wide. |
| 26 | + - Fix failing tests before reporting success. Do not report completion while story tests are failing. |
| 27 | +
|
| 28 | + ## Documentation Workflow |
| 29 | +
|
| 30 | + 1. Call **list-all-documentation** once at the start of the task to discover available component and docs IDs. |
| 31 | + 2. Call **get-documentation** with an \`id\` from that list to retrieve full component docs, props, usage examples, and stories. |
| 32 | + 3. Call **get-documentation-for-story** when you need additional docs from a specific story variant that was not included in the initial component documentation. |
| 33 | +
|
| 34 | + Use \`withStoryIds: true\` on **list-all-documentation** when you also need story IDs for tools like \`preview-stories\` or \`get-documentation-for-story\`. |
| 35 | +
|
| 36 | + ## Verification Rules |
| 37 | +
|
| 38 | + - Never assume component props, variants, or API shape. Retrieve documentation before using a component. |
| 39 | + - If a component or prop is not documented, do not invent it. Report that it was not found. |
| 40 | + - Only reference IDs returned by **list-all-documentation**. Do not guess IDs. |
| 41 | +
|
| 42 | + ## Multi-Source Requests |
| 43 | +
|
| 44 | + - When multiple Storybook sources are configured, **list-all-documentation** returns entries from all sources. |
| 45 | + - Use \`storybookId\` in **get-documentation** when you need to scope a request to one source." |
| 46 | + `); |
| 47 | + }); |
| 48 | + |
| 49 | + it('builds a coherent instruction set for dev only', () => { |
| 50 | + const instructions = buildServerInstructions({ |
| 51 | + devEnabled: true, |
| 52 | + testEnabled: false, |
| 53 | + docsEnabled: false, |
| 54 | + }); |
| 55 | + |
| 56 | + expect(instructions).toMatchInlineSnapshot(` |
| 57 | + "Follow these workflows when working with UI and/or Storybook. |
| 58 | +
|
| 59 | + ## UI Building and Story Writing Workflow |
| 60 | +
|
| 61 | + - Before creating or editing components or stories, call **get-storybook-story-instructions**. |
| 62 | + - Treat that tool's output as the source of truth for framework-specific imports, story patterns, and testing conventions. |
| 63 | + - After changing any component or story, call **preview-stories**. |
| 64 | + - Always include every returned preview URL in your user-facing response so the user can verify the visual result." |
| 65 | + `); |
| 66 | + }); |
| 67 | + |
| 68 | + it('builds a coherent instruction set for docs only', () => { |
| 69 | + const instructions = buildServerInstructions({ |
| 70 | + devEnabled: false, |
| 71 | + testEnabled: false, |
| 72 | + docsEnabled: true, |
| 73 | + }); |
| 74 | + |
| 75 | + expect(instructions).toMatchInlineSnapshot(` |
| 76 | + "Follow these workflows when working with UI and/or Storybook. |
| 77 | +
|
| 78 | + ## Documentation Workflow |
| 79 | +
|
| 80 | + 1. Call **list-all-documentation** once at the start of the task to discover available component and docs IDs. |
| 81 | + 2. Call **get-documentation** with an \`id\` from that list to retrieve full component docs, props, usage examples, and stories. |
| 82 | + 3. Call **get-documentation-for-story** when you need additional docs from a specific story variant that was not included in the initial component documentation. |
| 83 | +
|
| 84 | + Use \`withStoryIds: true\` on **list-all-documentation** when you also need story IDs for tools like \`preview-stories\` or \`get-documentation-for-story\`. |
| 85 | +
|
| 86 | + ## Verification Rules |
| 87 | +
|
| 88 | + - Never assume component props, variants, or API shape. Retrieve documentation before using a component. |
| 89 | + - If a component or prop is not documented, do not invent it. Report that it was not found. |
| 90 | + - Only reference IDs returned by **list-all-documentation**. Do not guess IDs. |
| 91 | +
|
| 92 | + ## Multi-Source Requests |
| 93 | +
|
| 94 | + - When multiple Storybook sources are configured, **list-all-documentation** returns entries from all sources. |
| 95 | + - Use \`storybookId\` in **get-documentation** when you need to scope a request to one source." |
| 96 | + `); |
| 97 | + }); |
| 98 | + |
| 99 | + it('builds a coherent instruction set for test only', () => { |
| 100 | + const instructions = buildServerInstructions({ |
| 101 | + devEnabled: false, |
| 102 | + testEnabled: true, |
| 103 | + docsEnabled: false, |
| 104 | + }); |
| 105 | + |
| 106 | + expect(instructions).toMatchInlineSnapshot(` |
| 107 | + "Follow these workflows when working with UI and/or Storybook. |
| 108 | +
|
| 109 | + ## Validation Workflow |
| 110 | +
|
| 111 | + - After each component or story change, run **run-story-tests**. |
| 112 | + - Use focused runs while iterating, then run a broad pass before final handoff when scope is unclear or wide. |
| 113 | + - Fix failing tests before reporting success. Do not report completion while story tests are failing." |
| 114 | + `); |
| 115 | + }); |
| 116 | + |
| 117 | + it('returns empty instructions when all toolsets are disabled', () => { |
| 118 | + const instructions = buildServerInstructions({ |
| 119 | + devEnabled: false, |
| 120 | + testEnabled: false, |
| 121 | + docsEnabled: false, |
| 122 | + }); |
| 123 | + |
| 124 | + expect(instructions).toBe(''); |
| 125 | + }); |
| 126 | +}); |
0 commit comments