teqo-backup/tests/unit/opencodeCommands.unit.spec.ts
Francisco Solla cb5854d17e feat(C187): dossiê Solla por instituição + boletim modelo (skill + builder) (Closes #1135)
Generaliza aditivamente o pipeline C186 (default município; specs verdes) via o
descritor scripts/lib/dossieUnit.mjs (municipality|institution), extrai o emit
A4/fit-guard para scripts/lib/buildPdf.mjs e a receita read-only para
scripts/lib/readOnlyExtract.mjs.

- Catálogo fail-closed src/lib/institutionCatalog.ts + institutionNameAliases.ts
  (seed UFBA/Correios/Enfermagem; escape one-off --slug/--name; dedup).
- Skill/command/subagente /dossie-solla-instituicao; eras A/B/C reusadas.
- Abrangência instituição × setor × rede nunca somada; era sem fonte vira página
  de lacuna explícita; lista capada declara "e mais N" (regra C188 no dono).
- Boletim modelo 1×A4 com fase junto ao valor, sem fontes, sem CTA; herda apenas
  fatos com fonte do dossiê (incl. falas do acervo read-only).
- Sem schema/migration/DB write; artefatos gitignored.
2026-09-17 19:25:13 -03:00

49 lines
2 KiB
TypeScript

import { existsSync, readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { describe, expect, it } from 'vitest'
// Programmatic guard for the OPS25 coupling: each `.opencode/commands/<name>.md`
// must keep pointing at the skill of the same name (`.agents/skills/<name>/SKILL.md`).
// The command body deliberately does NOT transcribe the skill — the canonical
// source is the SKILL.md. If a skill is renamed, this spec fails the build so the
// command is renamed together instead of breaking silently at the `/` prompt.
const repoRoot = process.cwd()
const commands = [
'work-issue',
'plan-issue',
'testing-audit',
'bug-fix',
'relatorio-cidade',
'dossie-solla-cidade',
'dossie-solla-instituicao',
] as const
describe('opencode commands couple to their skill by exact name', () => {
it.each(commands)('command /%s references the existing skill of the same name', (name) => {
const commandPath = resolve(repoRoot, `.opencode/commands/${name}.md`)
const skillPath = resolve(repoRoot, `.agents/skills/${name}/SKILL.md`)
expect(existsSync(commandPath), 'command file must exist').toBe(true)
expect(existsSync(skillPath), 'referenced skill must exist').toBe(true)
const content = readFileSync(commandPath, 'utf8')
expect(content, 'command must reference the skill by exact name').toContain(`\`${name}\``)
expect(content, 'command must pass arguments through').toContain('$ARGUMENTS')
expect(content, 'command must point at the canonical skill file').toContain(
`.agents/skills/${name}/SKILL.md`,
)
const frontmatter = content.match(/^---\n([\s\S]*?)\n---/)
expect(frontmatter, 'frontmatter must be delimited by ---').not.toBeNull()
expect(frontmatter![1], 'frontmatter must declare a TUI description').toMatch(
/^description: .+$/m,
)
expect(
frontmatter![1],
'frontmatter must NOT pin a model — the command inherits the session model (OPS101)',
).not.toMatch(/^\s*["']?model["']?\s*:/m)
})
})