|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { readFile } from 'node:fs/promises'; |
| 3 | +import { join } from 'node:path'; |
| 4 | +import { describe, test } from 'vitest'; |
| 5 | + |
| 6 | +const ROOT = join(import.meta.dirname, '..', '..'); |
| 7 | + |
| 8 | +type Contract = { |
| 9 | + id: string; |
| 10 | + requiredText: string; |
| 11 | +}; |
| 12 | + |
| 13 | +const SKILLS = [ |
| 14 | + { |
| 15 | + name: 'iOS Simulator', |
| 16 | + path: join(ROOT, 'skills', 'ios-simulator', 'SKILL.md'), |
| 17 | + contracts: [ |
| 18 | + { |
| 19 | + id: 'foreground platform open', |
| 20 | + requiredText: 'agent-device open <app-or-bundle-id> --platform ios --foreground', |
| 21 | + }, |
| 22 | + { |
| 23 | + id: 'initial interactive snapshot', |
| 24 | + requiredText: '`open` returns the initial interactive snapshot.', |
| 25 | + }, |
| 26 | + { id: 'current ref or selector', requiredText: 'Use its current refs or a selector.' }, |
| 27 | + { id: 'settled planned actions', requiredText: 'agent-device press @eN --settle' }, |
| 28 | + { id: 'type settle exception', requiredText: '`type` never takes `--settle`;' }, |
| 29 | + { |
| 30 | + id: 'end-state verification', |
| 31 | + requiredText: 'Verify the end state with a selector or exact text, then close:', |
| 32 | + }, |
| 33 | + { id: 'session close', requiredText: 'agent-device close' }, |
| 34 | + ] satisfies Contract[], |
| 35 | + }, |
| 36 | + { |
| 37 | + name: 'Android Emulator', |
| 38 | + path: join(ROOT, 'skills', 'android-emulator', 'SKILL.md'), |
| 39 | + contracts: [ |
| 40 | + { |
| 41 | + id: 'foreground platform open', |
| 42 | + requiredText: 'agent-device open <app-or-package-id> --platform android --foreground', |
| 43 | + }, |
| 44 | + { |
| 45 | + id: 'initial interactive snapshot', |
| 46 | + requiredText: '`open` returns the initial interactive snapshot.', |
| 47 | + }, |
| 48 | + { id: 'current ref or selector', requiredText: 'Use its current refs or a selector.' }, |
| 49 | + { id: 'settled planned actions', requiredText: 'agent-device press @eN --settle' }, |
| 50 | + { id: 'type settle exception', requiredText: '`type` never takes `--settle`;' }, |
| 51 | + { |
| 52 | + id: 'end-state verification', |
| 53 | + requiredText: 'Verify the end state with a selector or exact text, then close:', |
| 54 | + }, |
| 55 | + { id: 'session close', requiredText: 'agent-device close' }, |
| 56 | + ] satisfies Contract[], |
| 57 | + }, |
| 58 | +] as const; |
| 59 | + |
| 60 | +function assertSkillContract(content: string, contract: Contract): void { |
| 61 | + assert.ok(content.includes(contract.requiredText), `missing ${contract.id} guidance`); |
| 62 | +} |
| 63 | + |
| 64 | +describe('simulator skill contracts', () => { |
| 65 | + for (const skill of SKILLS) { |
| 66 | + test(`${skill.name} keeps its required workflow guidance`, async () => { |
| 67 | + const content = await readFile(skill.path, 'utf8'); |
| 68 | + for (const contract of skill.contracts) assertSkillContract(content, contract); |
| 69 | + }); |
| 70 | + |
| 71 | + for (const contract of skill.contracts) { |
| 72 | + test(`${skill.name} rejects a missing ${contract.id} contract`, async () => { |
| 73 | + const content = await readFile(skill.path, 'utf8'); |
| 74 | + const broken = content.replace(contract.requiredText, '[removed]'); |
| 75 | + assert.notEqual(broken, content, `test fixture must remove ${contract.id} guidance`); |
| 76 | + assert.throws( |
| 77 | + () => assertSkillContract(broken, contract), |
| 78 | + new RegExp(`missing ${contract.id} guidance`), |
| 79 | + ); |
| 80 | + }); |
| 81 | + } |
| 82 | + } |
| 83 | +}); |
0 commit comments