opencastle 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -9
- package/bin/cli.mjs +6 -0
- package/dist/cli/adapters/antigravity.d.ts +0 -1
- package/dist/cli/adapters/antigravity.d.ts.map +1 -1
- package/dist/cli/adapters/antigravity.js +2 -1
- package/dist/cli/adapters/antigravity.js.map +1 -1
- package/dist/cli/adapters/claude-code.d.ts +0 -1
- package/dist/cli/adapters/claude-code.d.ts.map +1 -1
- package/dist/cli/adapters/claude-code.js +0 -1
- package/dist/cli/adapters/claude-code.js.map +1 -1
- package/dist/cli/adapters/cursor.d.ts.map +1 -1
- package/dist/cli/adapters/cursor.js +8 -1
- package/dist/cli/adapters/cursor.js.map +1 -1
- package/dist/cli/adapters/opencode.d.ts +12 -5
- package/dist/cli/adapters/opencode.d.ts.map +1 -1
- package/dist/cli/adapters/opencode.js +17 -5
- package/dist/cli/adapters/opencode.js.map +1 -1
- package/dist/cli/adapters/rules-dir-base.d.ts +12 -1
- package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
- package/dist/cli/adapters/rules-dir-base.js +43 -57
- package/dist/cli/adapters/rules-dir-base.js.map +1 -1
- package/dist/cli/adapters/rules-dir-base.test.js +27 -18
- package/dist/cli/adapters/rules-dir-base.test.js.map +1 -1
- package/dist/cli/adapters/single-file-base.d.ts +11 -0
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +44 -14
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/adapters/vscode.d.ts +2 -1
- package/dist/cli/adapters/vscode.d.ts.map +1 -1
- package/dist/cli/adapters/vscode.js +2 -1
- package/dist/cli/adapters/vscode.js.map +1 -1
- package/dist/cli/adapters/windsurf.d.ts.map +1 -1
- package/dist/cli/adapters/windsurf.js +11 -1
- package/dist/cli/adapters/windsurf.js.map +1 -1
- package/dist/cli/agent-plugin.d.ts +119 -0
- package/dist/cli/agent-plugin.d.ts.map +1 -0
- package/dist/cli/agent-plugin.js +449 -0
- package/dist/cli/agent-plugin.js.map +1 -0
- package/dist/cli/agent-plugin.test.d.ts +2 -0
- package/dist/cli/agent-plugin.test.d.ts.map +1 -0
- package/dist/cli/agent-plugin.test.js +227 -0
- package/dist/cli/agent-plugin.test.js.map +1 -0
- package/dist/cli/baseline.d.ts.map +1 -1
- package/dist/cli/baseline.js +114 -34
- package/dist/cli/baseline.js.map +1 -1
- package/dist/cli/ci.d.ts.map +1 -1
- package/dist/cli/ci.js +18 -4
- package/dist/cli/ci.js.map +1 -1
- package/dist/cli/codex-target.test.js +14 -1
- package/dist/cli/codex-target.test.js.map +1 -1
- package/dist/cli/convoy/gates.d.ts +2 -20
- package/dist/cli/convoy/gates.d.ts.map +1 -1
- package/dist/cli/convoy/gates.js +3 -111
- package/dist/cli/convoy/gates.js.map +1 -1
- package/dist/cli/copy.d.ts +0 -8
- package/dist/cli/copy.d.ts.map +1 -1
- package/dist/cli/copy.js +0 -21
- package/dist/cli/copy.js.map +1 -1
- package/dist/cli/dispatcher.test.js +2 -2
- package/dist/cli/dispatcher.test.js.map +1 -1
- package/dist/cli/docs-accuracy.test.js +2 -0
- package/dist/cli/docs-accuracy.test.js.map +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +2 -0
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/doctor.test.js +2 -2
- package/dist/cli/doctor.test.js.map +1 -1
- package/dist/cli/explain.d.ts +5 -0
- package/dist/cli/explain.d.ts.map +1 -1
- package/dist/cli/explain.js +38 -2
- package/dist/cli/explain.js.map +1 -1
- package/dist/cli/init.test.js +78 -42
- package/dist/cli/init.test.js.map +1 -1
- package/dist/cli/layers.d.ts +8 -0
- package/dist/cli/layers.d.ts.map +1 -1
- package/dist/cli/layers.js +130 -13
- package/dist/cli/layers.js.map +1 -1
- package/dist/cli/layers.test.js +2 -2
- package/dist/cli/layers.test.js.map +1 -1
- package/dist/cli/legacy-install.test.js +8 -1
- package/dist/cli/legacy-install.test.js.map +1 -1
- package/dist/cli/lesson-command.test.d.ts +2 -0
- package/dist/cli/lesson-command.test.d.ts.map +1 -0
- package/dist/cli/lesson-command.test.js +100 -0
- package/dist/cli/lesson-command.test.js.map +1 -0
- package/dist/cli/lesson.d.ts +0 -9
- package/dist/cli/lesson.d.ts.map +1 -1
- package/dist/cli/lesson.js +212 -276
- package/dist/cli/lesson.js.map +1 -1
- package/dist/cli/lessons.d.ts +134 -0
- package/dist/cli/lessons.d.ts.map +1 -0
- package/dist/cli/lessons.js +493 -0
- package/dist/cli/lessons.js.map +1 -0
- package/dist/cli/lessons.test.d.ts +2 -0
- package/dist/cli/lessons.test.d.ts.map +1 -0
- package/dist/cli/lessons.test.js +214 -0
- package/dist/cli/lessons.test.js.map +1 -0
- package/dist/cli/managed-paths.d.ts.map +1 -1
- package/dist/cli/managed-paths.js +3 -1
- package/dist/cli/managed-paths.js.map +1 -1
- package/dist/cli/mcp-audit.d.ts.map +1 -1
- package/dist/cli/mcp-audit.js +2 -0
- package/dist/cli/mcp-audit.js.map +1 -1
- package/dist/cli/mcp-upgrade.test.js +24 -1
- package/dist/cli/mcp-upgrade.test.js.map +1 -1
- package/dist/cli/mcp.d.ts.map +1 -1
- package/dist/cli/mcp.js +22 -3
- package/dist/cli/mcp.js.map +1 -1
- package/dist/cli/pack-plugins.d.ts +8 -0
- package/dist/cli/pack-plugins.d.ts.map +1 -0
- package/dist/cli/pack-plugins.js +70 -0
- package/dist/cli/pack-plugins.js.map +1 -0
- package/dist/cli/plugin-command.test.d.ts +2 -0
- package/dist/cli/plugin-command.test.d.ts.map +1 -0
- package/dist/cli/plugin-command.test.js +114 -0
- package/dist/cli/plugin-command.test.js.map +1 -0
- package/dist/cli/plugin.d.ts +30 -0
- package/dist/cli/plugin.d.ts.map +1 -0
- package/dist/cli/plugin.js +291 -0
- package/dist/cli/plugin.js.map +1 -0
- package/dist/cli/promote-command.test.d.ts +2 -0
- package/dist/cli/promote-command.test.d.ts.map +1 -0
- package/dist/cli/promote-command.test.js +151 -0
- package/dist/cli/promote-command.test.js.map +1 -0
- package/dist/cli/promote.d.ts +12 -0
- package/dist/cli/promote.d.ts.map +1 -0
- package/dist/cli/promote.js +364 -0
- package/dist/cli/promote.js.map +1 -0
- package/dist/cli/secret-scan.d.ts +21 -0
- package/dist/cli/secret-scan.d.ts.map +1 -0
- package/dist/cli/secret-scan.js +114 -0
- package/dist/cli/secret-scan.js.map +1 -0
- package/dist/cli/sync-check.d.ts.map +1 -1
- package/dist/cli/sync-check.js +9 -0
- package/dist/cli/sync-check.js.map +1 -1
- package/dist/cli/sync-check.test.js +5 -4
- package/dist/cli/sync-check.test.js.map +1 -1
- package/dist/cli/team-commands.test.js +14 -2
- package/dist/cli/team-commands.test.js.map +1 -1
- package/dist/cli/team-sources.test.js +10 -0
- package/dist/cli/team-sources.test.js.map +1 -1
- package/dist/cli/types.d.ts +1 -1
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +18 -0
- package/dist/cli/update.js.map +1 -1
- package/dist/cli/windsurf-target.test.d.ts +2 -0
- package/dist/cli/windsurf-target.test.d.ts.map +1 -0
- package/dist/cli/windsurf-target.test.js +62 -0
- package/dist/cli/windsurf-target.test.js.map +1 -0
- package/dist/orchestrator/plugins/agent-plugins.test.d.ts +2 -0
- package/dist/orchestrator/plugins/agent-plugins.test.d.ts.map +1 -0
- package/dist/orchestrator/plugins/agent-plugins.test.js +32 -0
- package/dist/orchestrator/plugins/agent-plugins.test.js.map +1 -0
- package/dist/orchestrator/plugins/registry.test.d.ts +2 -0
- package/dist/orchestrator/plugins/registry.test.d.ts.map +1 -0
- package/dist/orchestrator/plugins/registry.test.js +37 -0
- package/dist/orchestrator/plugins/registry.test.js.map +1 -0
- package/package.json +2 -1
- package/src/cli/adapters/antigravity.ts +2 -1
- package/src/cli/adapters/claude-code.ts +0 -1
- package/src/cli/adapters/cursor.ts +8 -1
- package/src/cli/adapters/opencode.ts +18 -6
- package/src/cli/adapters/rules-dir-base.test.ts +28 -18
- package/src/cli/adapters/rules-dir-base.ts +51 -90
- package/src/cli/adapters/single-file-base.ts +53 -14
- package/src/cli/adapters/vscode.ts +2 -1
- package/src/cli/adapters/windsurf.ts +11 -1
- package/src/cli/agent-plugin.test.ts +267 -0
- package/src/cli/agent-plugin.ts +469 -0
- package/src/cli/baseline.ts +115 -32
- package/src/cli/ci.ts +19 -4
- package/src/cli/codex-target.test.ts +15 -1
- package/src/cli/convoy/gates.ts +9 -142
- package/src/cli/copy.ts +0 -25
- package/src/cli/dispatcher.test.ts +2 -2
- package/src/cli/docs-accuracy.test.ts +2 -0
- package/src/cli/doctor.test.ts +2 -2
- package/src/cli/doctor.ts +2 -0
- package/src/cli/explain.ts +36 -2
- package/src/cli/fixtures/lessons-template-1.0.md +70 -0
- package/src/cli/init.test.ts +82 -42
- package/src/cli/layers.test.ts +2 -2
- package/src/cli/layers.ts +144 -14
- package/src/cli/legacy-install.test.ts +11 -1
- package/src/cli/lesson-command.test.ts +117 -0
- package/src/cli/lesson.ts +215 -266
- package/src/cli/lessons.test.ts +254 -0
- package/src/cli/lessons.ts +540 -0
- package/src/cli/managed-paths.ts +3 -1
- package/src/cli/mcp-audit.ts +2 -0
- package/src/cli/mcp-upgrade.test.ts +26 -1
- package/src/cli/mcp.ts +22 -3
- package/src/cli/pack-plugins.ts +70 -0
- package/src/cli/plugin-command.test.ts +125 -0
- package/src/cli/plugin.ts +309 -0
- package/src/cli/promote-command.test.ts +170 -0
- package/src/cli/promote.ts +371 -0
- package/src/cli/secret-scan.ts +154 -0
- package/src/cli/sync-check.test.ts +5 -4
- package/src/cli/sync-check.ts +9 -0
- package/src/cli/team-commands.test.ts +18 -2
- package/src/cli/team-sources.test.ts +11 -0
- package/src/cli/types.ts +1 -1
- package/src/cli/update.ts +20 -0
- package/src/cli/windsurf-target.test.ts +70 -0
- package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
- package/src/orchestrator/agents/researcher.agent.md +1 -1
- package/src/orchestrator/customizations/LESSONS-LEARNED.md +10 -66
- package/src/orchestrator/customizations/README.md +2 -1
- package/src/orchestrator/customizations/logs/README.md +1 -1
- package/src/orchestrator/plugins/agent-plugins.test.ts +34 -0
- package/src/orchestrator/plugins/astro/mcp.json +9 -0
- package/src/orchestrator/plugins/astro/plugin.json +21 -0
- package/src/orchestrator/plugins/chrome-devtools/mcp.json +13 -0
- package/src/orchestrator/plugins/chrome-devtools/plugin.json +21 -0
- package/src/orchestrator/plugins/cloudflare/mcp.json +9 -0
- package/src/orchestrator/plugins/cloudflare/plugin.json +21 -0
- package/src/orchestrator/plugins/contentful/mcp.json +13 -0
- package/src/orchestrator/plugins/contentful/plugin.json +21 -0
- package/src/orchestrator/plugins/convex/mcp.json +15 -0
- package/src/orchestrator/plugins/convex/plugin.json +21 -0
- package/src/orchestrator/plugins/coolify/mcp.json +13 -0
- package/src/orchestrator/plugins/coolify/plugin.json +25 -0
- package/src/orchestrator/plugins/cypress/plugin.json +21 -0
- package/src/orchestrator/plugins/drizzle/plugin.json +21 -0
- package/src/orchestrator/plugins/expo/mcp.json +9 -0
- package/src/orchestrator/plugins/expo/plugin.json +21 -0
- package/src/orchestrator/plugins/figma/mcp.json +9 -0
- package/src/orchestrator/plugins/figma/plugin.json +21 -0
- package/src/orchestrator/plugins/hetzner/plugin.json +24 -0
- package/src/orchestrator/plugins/jira/mcp.json +9 -0
- package/src/orchestrator/plugins/jira/plugin.json +21 -0
- package/src/orchestrator/plugins/linear/mcp.json +9 -0
- package/src/orchestrator/plugins/linear/plugin.json +21 -0
- package/src/orchestrator/plugins/netlify/mcp.json +13 -0
- package/src/orchestrator/plugins/netlify/plugin.json +21 -0
- package/src/orchestrator/plugins/nextjs/mcp.json +13 -0
- package/src/orchestrator/plugins/nextjs/plugin.json +21 -0
- package/src/orchestrator/plugins/notion/mcp.json +9 -0
- package/src/orchestrator/plugins/notion/plugin.json +21 -0
- package/src/orchestrator/plugins/nx/mcp.json +14 -0
- package/src/orchestrator/plugins/nx/plugin.json +21 -0
- package/src/orchestrator/plugins/playwright/mcp.json +13 -0
- package/src/orchestrator/plugins/playwright/plugin.json +21 -0
- package/src/orchestrator/plugins/prisma/mcp.json +14 -0
- package/src/orchestrator/plugins/prisma/plugin.json +21 -0
- package/src/orchestrator/plugins/registry.test.ts +42 -0
- package/src/orchestrator/plugins/resend/mcp.json +13 -0
- package/src/orchestrator/plugins/resend/plugin.json +24 -0
- package/src/orchestrator/plugins/sanity/mcp.json +9 -0
- package/src/orchestrator/plugins/sanity/plugin.json +21 -0
- package/src/orchestrator/plugins/sentry/mcp.json +12 -0
- package/src/orchestrator/plugins/sentry/plugin.json +24 -0
- package/src/orchestrator/plugins/slack/mcp.json +13 -0
- package/src/orchestrator/plugins/slack/plugin.json +24 -0
- package/src/orchestrator/plugins/strapi/mcp.json +13 -0
- package/src/orchestrator/plugins/strapi/plugin.json +21 -0
- package/src/orchestrator/plugins/stripe/mcp.json +9 -0
- package/src/orchestrator/plugins/stripe/plugin.json +21 -0
- package/src/orchestrator/plugins/supabase/mcp.json +9 -0
- package/src/orchestrator/plugins/supabase/plugin.json +21 -0
- package/src/orchestrator/plugins/teams/plugin.json +24 -0
- package/src/orchestrator/plugins/trello/mcp.json +13 -0
- package/src/orchestrator/plugins/trello/plugin.json +25 -0
- package/src/orchestrator/plugins/turborepo/plugin.json +21 -0
- package/src/orchestrator/plugins/vercel/mcp.json +9 -0
- package/src/orchestrator/plugins/vercel/plugin.json +21 -0
- package/src/orchestrator/plugins/vitest/plugin.json +21 -0
- package/src/orchestrator/skill-config-links.test.ts +2 -1
- package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +1 -1
- package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
- package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
- package/src/orchestrator/skills/memory-merger/SKILL.md +17 -21
- package/src/orchestrator/skills/self-improvement/LESSON-CATEGORIES.md +44 -23
- package/src/orchestrator/skills/self-improvement/SKILL.md +30 -15
- /package/src/orchestrator/plugins/astro/{SKILL.md → skills/astro-framework/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/chrome-devtools/{SKILL.md → skills/browser-testing/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/cloudflare/{SKILL.md → skills/cloudflare-platform/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/contentful/{SKILL.md → skills/contentful-cms/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/convex/{SKILL.md → skills/convex-database/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/coolify/{SKILL.md → skills/coolify-deployment/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/cypress/{SKILL.md → skills/cypress-testing/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/drizzle/{SKILL.md → skills/drizzle-orm/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/expo/{SKILL.md → skills/expo-development/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/figma/{SKILL.md → skills/figma-design/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/hetzner/{SKILL.md → skills/hetzner-cloud/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/jira/{SKILL.md → skills/jira-management/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/linear/{SKILL.md → skills/linear-task-management/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/netlify/{SKILL.md → skills/netlify-deployment/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/nextjs/{SKILL.md → skills/nextjs-framework/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/notion/{SKILL.md → skills/notion-knowledge-management/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/nx/{SKILL.md → skills/nx-workspace/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/playwright/{SKILL.md → skills/playwright-testing/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/prisma/{SKILL.md → skills/prisma-database/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/resend/{SKILL.md → skills/resend-email/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/sanity/{SKILL.md → skills/sanity-cms/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/sentry/{SKILL.md → skills/sentry-monitoring/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/slack/{SKILL.md → skills/slack-notifications/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/strapi/{SKILL.md → skills/strapi-cms/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/stripe/{SKILL.md → skills/stripe-payments/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/supabase/{SKILL.md → skills/supabase-database/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/teams/{SKILL.md → skills/teams-notifications/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/trello/{SKILL.md → skills/trello-task-management/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/turborepo/{SKILL.md → skills/turborepo-monorepo/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/vercel/{SKILL.md → skills/vercel-deployment/SKILL.md} +0 -0
- /package/src/orchestrator/plugins/vitest/{SKILL.md → skills/vitest-testing/SKILL.md} +0 -0
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, readdirSync, existsSync, rmSync } from 'node:fs'
|
|
13
13
|
import { tmpdir } from 'node:os'
|
|
14
|
-
import { join, resolve } from 'node:path'
|
|
14
|
+
import { basename, join, resolve } from 'node:path'
|
|
15
15
|
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
16
16
|
|
|
17
17
|
vi.mock('./prompt.js', async () => {
|
|
@@ -265,6 +265,13 @@ describe('sync never edits what the user wrote in .opencastle/', () => {
|
|
|
265
265
|
const init = (await import('./init.js')).default
|
|
266
266
|
await init({ pkgRoot, args: ['--yes'] })
|
|
267
267
|
|
|
268
|
+
// A lesson an agent recorded is the team's writing too.
|
|
269
|
+
mkdirSync(join(dir, '.opencastle', 'lessons'), { recursive: true })
|
|
270
|
+
writeFileSync(
|
|
271
|
+
join(dir, '.opencastle', 'lessons', 'LES-001-quote-variables.md'),
|
|
272
|
+
'---\nid: "LES-001"\ntitle: "Quote variables"\ncategory: "terminal"\nseverity: "low"\nadded: "2026-01-01"\n---\n\n**Problem:** spaces.\n',
|
|
273
|
+
)
|
|
274
|
+
|
|
268
275
|
// Sentinel every file, and remember the exact bytes.
|
|
269
276
|
const before = new Map<string, string>()
|
|
270
277
|
const walk = (d: string): string[] =>
|
|
@@ -273,6 +280,9 @@ describe('sync never edits what the user wrote in .opencastle/', () => {
|
|
|
273
280
|
)
|
|
274
281
|
for (const f of walk(join(dir, '.opencastle'))) {
|
|
275
282
|
if (!f.endsWith('.md')) continue
|
|
283
|
+
// The lessons index is compiled from `lessons/` — it says so on its
|
|
284
|
+
// first line, and `sync` rewrites it, as it rewrites the lock.
|
|
285
|
+
if (basename(f) === 'LESSONS-LEARNED.md') continue
|
|
276
286
|
const text = `${readFileSync(f, 'utf8')}\n<!-- SENTINEL -->\n`
|
|
277
287
|
writeFileSync(f, text)
|
|
278
288
|
before.set(f, text)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `opencastle lesson`, as agents call it.
|
|
3
|
+
*
|
|
4
|
+
* The command is hidden from help because people rarely type it — the
|
|
5
|
+
* generated instructions tell agents to. That made it the least exercised
|
|
6
|
+
* writer of a file every agent reads first: it had no test at all, and the
|
|
7
|
+
* skill describing it told agents to check their entry with `tail -1`, which
|
|
8
|
+
* showed the index row, not the entry.
|
|
9
|
+
*/
|
|
10
|
+
import { execFileSync, spawnSync } from 'node:child_process'
|
|
11
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
12
|
+
import { tmpdir } from 'node:os'
|
|
13
|
+
import { join, resolve } from 'node:path'
|
|
14
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
15
|
+
import { checkLessons } from './lessons.js'
|
|
16
|
+
|
|
17
|
+
const pkgRoot = resolve(import.meta.dirname, '..', '..')
|
|
18
|
+
const cli = join(pkgRoot, 'bin', 'cli.mjs')
|
|
19
|
+
const built = existsSync(join(pkgRoot, 'dist', 'cli', 'lesson.js'))
|
|
20
|
+
|
|
21
|
+
describe.skipIf(!built)('opencastle lesson', () => {
|
|
22
|
+
let project: string
|
|
23
|
+
const sh = (...args: string[]): string =>
|
|
24
|
+
execFileSync('git', args, { cwd: project, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()
|
|
25
|
+
const lesson = (...args: string[]) => spawnSync('node', [cli, 'lesson', ...args], { cwd: project, encoding: 'utf8' })
|
|
26
|
+
const files = (): string[] => readdirSync(join(project, '.opencastle', 'lessons')).sort()
|
|
27
|
+
const index = (): string => readFileSync(join(project, '.opencastle', 'LESSONS-LEARNED.md'), 'utf8')
|
|
28
|
+
const base = ['--title', 'Quote shell variables', '--category', 'terminal', '--severity', 'medium', '--problem', 'Paths with spaces break']
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
project = mkdtempSync(join(tmpdir(), 'oc-lesson-cmd-'))
|
|
32
|
+
sh('init', '-q')
|
|
33
|
+
sh('config', 'user.email', 't@example.com')
|
|
34
|
+
sh('config', 'user.name', 'T')
|
|
35
|
+
mkdirSync(join(project, '.opencastle'))
|
|
36
|
+
mkdirSync(join(project, 'scripts'))
|
|
37
|
+
writeFileSync(join(project, 'scripts', 'clean.sh'), 'rm -rf "$DIR/old"\n')
|
|
38
|
+
writeFileSync(
|
|
39
|
+
join(project, '.opencastle', 'LESSONS-LEARNED.md'),
|
|
40
|
+
readFileSync(join(import.meta.dirname, 'fixtures', 'lessons-template-1.0.md'), 'utf8'),
|
|
41
|
+
)
|
|
42
|
+
sh('add', '.')
|
|
43
|
+
sh('commit', '-qm', 'init')
|
|
44
|
+
})
|
|
45
|
+
afterEach(() => rmSync(project, { recursive: true, force: true }))
|
|
46
|
+
|
|
47
|
+
it('writes one file, named by date and title, and lists it in the index', () => {
|
|
48
|
+
const out = lesson(...base, '--cite', 'scripts/clean.sh:1')
|
|
49
|
+
expect(out.status).toBe(0)
|
|
50
|
+
const [file] = files()
|
|
51
|
+
expect(file).toMatch(/^\d{4}-\d{2}-\d{2}-quote-shell-variables\.md$/)
|
|
52
|
+
const text = readFileSync(join(project, '.opencastle', 'lessons', file), 'utf8')
|
|
53
|
+
expect(text).toContain('citations:\n - "scripts/clean.sh:1"')
|
|
54
|
+
expect(text).toMatch(/fingerprints:\n scripts\/clean\.sh: "[0-9a-f]{12}"/)
|
|
55
|
+
expect(index()).toContain('**Quote shell variables** — `medium`')
|
|
56
|
+
expect(out.stdout).toContain(file.replace(/\.md$/, ''))
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('names two lessons with one title apart, so branches never collide', () => {
|
|
60
|
+
lesson(...base)
|
|
61
|
+
lesson(...base)
|
|
62
|
+
expect(files()).toHaveLength(2)
|
|
63
|
+
expect(files().some((f) => /-quote-shell-variables-2\.md$/.test(f))).toBe(true)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('refuses a citation that does not exist, and writes nothing', () => {
|
|
67
|
+
const out = lesson(...base, '--cite', 'scripts/missing.sh')
|
|
68
|
+
expect(out.status).toBe(1)
|
|
69
|
+
expect(out.stderr).toContain('scripts/missing.sh does not exist')
|
|
70
|
+
expect(existsSync(join(project, '.opencastle', 'lessons'))).toBe(false)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('refuses a lesson that would commit a credential', () => {
|
|
74
|
+
const out = lesson(...base, '--correct', 'use AKIAIOSFODNN7EXAMPLE as the key')
|
|
75
|
+
expect(out.status).toBe(1)
|
|
76
|
+
expect(out.stderr).toMatch(/looks like a AWS Access Key/)
|
|
77
|
+
expect(existsSync(join(project, '.opencastle', 'lessons'))).toBe(false)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('verify clears what doctor said about changed code', () => {
|
|
81
|
+
lesson(...base, '--cite', 'scripts/clean.sh')
|
|
82
|
+
writeFileSync(join(project, 'scripts', 'clean.sh'), 'rm -rf -- "$DIR/old"\n')
|
|
83
|
+
expect(checkLessons(project).warning).toBe(true)
|
|
84
|
+
const id = files()[0].replace(/\.md$/, '')
|
|
85
|
+
expect(lesson('verify', id).status).toBe(0)
|
|
86
|
+
expect(checkLessons(project).warning).toBeUndefined()
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('archive moves a lesson out of the list agents read, and keeps it on record', () => {
|
|
90
|
+
lesson(...base)
|
|
91
|
+
const id = files()[0].replace(/\.md$/, '')
|
|
92
|
+
expect(lesson('archive', id, '--into', 'scripts/clean.sh').status).toBe(0)
|
|
93
|
+
const [active, archived] = index().split('## Archived')
|
|
94
|
+
expect(active).not.toContain('Quote shell variables')
|
|
95
|
+
expect(archived).toContain('**Quote shell variables** → `scripts/clean.sh`')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('moves an old single-file log into lesson files before adding to it', () => {
|
|
99
|
+
writeFileSync(
|
|
100
|
+
join(project, '.opencastle', 'LESSONS-LEARNED.md'),
|
|
101
|
+
'# Lessons Learned\n\n### LES-004: Never push to main\n\n| Field | Value |\n|---|---|\n| **Category** | `git` |\n| **Added** | 2026-03-02 |\n| **Severity** | `high` |\n\n**Problem:** It was pushed.\n',
|
|
102
|
+
)
|
|
103
|
+
const out = lesson(...base)
|
|
104
|
+
expect(out.status).toBe(0)
|
|
105
|
+
expect(out.stdout).toContain('Moved 1 lesson(s)')
|
|
106
|
+
expect(files()).toEqual(expect.arrayContaining(['LES-004-never-push-to-main.md']))
|
|
107
|
+
expect(index()).toContain('## git')
|
|
108
|
+
expect(existsSync(join(project, '.opencastle', 'LESSONS-LEARNED.md.opencastle-backup'))).toBe(true)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('--dry-run prints the lesson and writes nothing', () => {
|
|
112
|
+
const out = lesson(...base, '--dry-run')
|
|
113
|
+
expect(out.status).toBe(0)
|
|
114
|
+
expect(out.stdout).toContain('title: "Quote shell variables"')
|
|
115
|
+
expect(existsSync(join(project, '.opencastle', 'lessons'))).toBe(false)
|
|
116
|
+
})
|
|
117
|
+
})
|