opencastle 0.38.1 → 1.0.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.
Files changed (289) hide show
  1. package/README.md +81 -1
  2. package/bin/cli.mjs +20 -3
  3. package/dist/cli/adapters/antigravity.d.ts +1 -1
  4. package/dist/cli/adapters/antigravity.d.ts.map +1 -1
  5. package/dist/cli/adapters/claude-code.d.ts +1 -1
  6. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  7. package/dist/cli/adapters/codex.d.ts +1 -1
  8. package/dist/cli/adapters/codex.d.ts.map +1 -1
  9. package/dist/cli/adapters/cursor.d.ts +1 -1
  10. package/dist/cli/adapters/cursor.d.ts.map +1 -1
  11. package/dist/cli/adapters/opencode.d.ts +1 -1
  12. package/dist/cli/adapters/opencode.d.ts.map +1 -1
  13. package/dist/cli/adapters/rules-dir-base.d.ts +3 -2
  14. package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
  15. package/dist/cli/adapters/rules-dir-base.js +13 -25
  16. package/dist/cli/adapters/rules-dir-base.js.map +1 -1
  17. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  18. package/dist/cli/adapters/single-file-base.js +30 -43
  19. package/dist/cli/adapters/single-file-base.js.map +1 -1
  20. package/dist/cli/adapters/vscode.d.ts +3 -2
  21. package/dist/cli/adapters/vscode.d.ts.map +1 -1
  22. package/dist/cli/adapters/vscode.js +19 -71
  23. package/dist/cli/adapters/vscode.js.map +1 -1
  24. package/dist/cli/adapters/windsurf.d.ts +1 -1
  25. package/dist/cli/adapters/windsurf.d.ts.map +1 -1
  26. package/dist/cli/baseline.d.ts +3 -0
  27. package/dist/cli/baseline.d.ts.map +1 -0
  28. package/dist/cli/baseline.js +280 -0
  29. package/dist/cli/baseline.js.map +1 -0
  30. package/dist/cli/bootstrap.d.ts +1 -0
  31. package/dist/cli/bootstrap.d.ts.map +1 -1
  32. package/dist/cli/bootstrap.js +1 -1
  33. package/dist/cli/bootstrap.js.map +1 -1
  34. package/dist/cli/ci.d.ts +18 -0
  35. package/dist/cli/ci.d.ts.map +1 -0
  36. package/dist/cli/ci.js +279 -0
  37. package/dist/cli/ci.js.map +1 -0
  38. package/dist/cli/dispatcher.test.js +2 -2
  39. package/dist/cli/dispatcher.test.js.map +1 -1
  40. package/dist/cli/docs-accuracy.test.js +5 -0
  41. package/dist/cli/docs-accuracy.test.js.map +1 -1
  42. package/dist/cli/doctor.d.ts +3 -3
  43. package/dist/cli/doctor.d.ts.map +1 -1
  44. package/dist/cli/doctor.js +66 -9
  45. package/dist/cli/doctor.js.map +1 -1
  46. package/dist/cli/explain.d.ts +3 -0
  47. package/dist/cli/explain.d.ts.map +1 -0
  48. package/dist/cli/explain.js +210 -0
  49. package/dist/cli/explain.js.map +1 -0
  50. package/dist/cli/fleet.d.ts +30 -0
  51. package/dist/cli/fleet.d.ts.map +1 -0
  52. package/dist/cli/fleet.js +149 -0
  53. package/dist/cli/fleet.js.map +1 -0
  54. package/dist/cli/github-report.d.ts +49 -0
  55. package/dist/cli/github-report.d.ts.map +1 -0
  56. package/dist/cli/github-report.js +161 -0
  57. package/dist/cli/github-report.js.map +1 -0
  58. package/dist/cli/github-report.test.d.ts +2 -0
  59. package/dist/cli/github-report.test.d.ts.map +1 -0
  60. package/dist/cli/github-report.test.js +146 -0
  61. package/dist/cli/github-report.test.js.map +1 -0
  62. package/dist/cli/init.d.ts.map +1 -1
  63. package/dist/cli/init.js +135 -94
  64. package/dist/cli/init.js.map +1 -1
  65. package/dist/cli/init.test.js +26 -25
  66. package/dist/cli/init.test.js.map +1 -1
  67. package/dist/cli/layers.d.ts +152 -0
  68. package/dist/cli/layers.d.ts.map +1 -0
  69. package/dist/cli/layers.js +932 -0
  70. package/dist/cli/layers.js.map +1 -0
  71. package/dist/cli/layers.test.d.ts +2 -0
  72. package/dist/cli/layers.test.d.ts.map +1 -0
  73. package/dist/cli/layers.test.js +483 -0
  74. package/dist/cli/layers.test.js.map +1 -0
  75. package/dist/cli/lock.d.ts +130 -0
  76. package/dist/cli/lock.d.ts.map +1 -0
  77. package/dist/cli/lock.js +320 -0
  78. package/dist/cli/lock.js.map +1 -0
  79. package/dist/cli/mcp-audit.d.ts +164 -0
  80. package/dist/cli/mcp-audit.d.ts.map +1 -0
  81. package/dist/cli/mcp-audit.js +504 -0
  82. package/dist/cli/mcp-audit.js.map +1 -0
  83. package/dist/cli/mcp-audit.test.d.ts +2 -0
  84. package/dist/cli/mcp-audit.test.d.ts.map +1 -0
  85. package/dist/cli/mcp-audit.test.js +215 -0
  86. package/dist/cli/mcp-audit.test.js.map +1 -0
  87. package/dist/cli/mcp-upgrade.test.d.ts +2 -0
  88. package/dist/cli/mcp-upgrade.test.d.ts.map +1 -0
  89. package/dist/cli/mcp-upgrade.test.js +118 -0
  90. package/dist/cli/mcp-upgrade.test.js.map +1 -0
  91. package/dist/cli/mcp.d.ts +74 -5
  92. package/dist/cli/mcp.d.ts.map +1 -1
  93. package/dist/cli/mcp.js +340 -32
  94. package/dist/cli/mcp.js.map +1 -1
  95. package/dist/cli/policy.d.ts +58 -0
  96. package/dist/cli/policy.d.ts.map +1 -0
  97. package/dist/cli/policy.js +194 -0
  98. package/dist/cli/policy.js.map +1 -0
  99. package/dist/cli/publish-workflow.test.js +55 -1
  100. package/dist/cli/publish-workflow.test.js.map +1 -1
  101. package/dist/cli/remove.d.ts.map +1 -1
  102. package/dist/cli/remove.js +3 -2
  103. package/dist/cli/remove.js.map +1 -1
  104. package/dist/cli/review.d.ts +25 -0
  105. package/dist/cli/review.d.ts.map +1 -0
  106. package/dist/cli/review.js +437 -0
  107. package/dist/cli/review.js.map +1 -0
  108. package/dist/cli/status.d.ts +2 -0
  109. package/dist/cli/status.d.ts.map +1 -1
  110. package/dist/cli/status.js +25 -4
  111. package/dist/cli/status.js.map +1 -1
  112. package/dist/cli/status.test.js +5 -3
  113. package/dist/cli/status.test.js.map +1 -1
  114. package/dist/cli/sync-check.d.ts +16 -1
  115. package/dist/cli/sync-check.d.ts.map +1 -1
  116. package/dist/cli/sync-check.js +219 -13
  117. package/dist/cli/sync-check.js.map +1 -1
  118. package/dist/cli/sync-check.test.js +14 -8
  119. package/dist/cli/sync-check.test.js.map +1 -1
  120. package/dist/cli/sync.d.ts.map +1 -1
  121. package/dist/cli/sync.js +2 -0
  122. package/dist/cli/sync.js.map +1 -1
  123. package/dist/cli/team-ci.test.d.ts +2 -0
  124. package/dist/cli/team-ci.test.d.ts.map +1 -0
  125. package/dist/cli/team-ci.test.js +169 -0
  126. package/dist/cli/team-ci.test.js.map +1 -0
  127. package/dist/cli/team-commands.test.d.ts +2 -0
  128. package/dist/cli/team-commands.test.d.ts.map +1 -0
  129. package/dist/cli/team-commands.test.js +233 -0
  130. package/dist/cli/team-commands.test.js.map +1 -0
  131. package/dist/cli/team-config.d.ts +88 -0
  132. package/dist/cli/team-config.d.ts.map +1 -0
  133. package/dist/cli/team-config.js +261 -0
  134. package/dist/cli/team-config.js.map +1 -0
  135. package/dist/cli/team-health.d.ts +49 -0
  136. package/dist/cli/team-health.d.ts.map +1 -0
  137. package/dist/cli/team-health.js +205 -0
  138. package/dist/cli/team-health.js.map +1 -0
  139. package/dist/cli/team-sources.test.d.ts +2 -0
  140. package/dist/cli/team-sources.test.d.ts.map +1 -0
  141. package/dist/cli/team-sources.test.js +542 -0
  142. package/dist/cli/team-sources.test.js.map +1 -0
  143. package/dist/cli/types.d.ts +16 -2
  144. package/dist/cli/types.d.ts.map +1 -1
  145. package/dist/cli/types.js.map +1 -1
  146. package/dist/cli/update.d.ts.map +1 -1
  147. package/dist/cli/update.js +204 -44
  148. package/dist/cli/update.js.map +1 -1
  149. package/dist/cli/version-range.d.ts +24 -0
  150. package/dist/cli/version-range.d.ts.map +1 -0
  151. package/dist/cli/version-range.js +157 -0
  152. package/dist/cli/version-range.js.map +1 -0
  153. package/dist/cli/website-plugins.test.d.ts +2 -0
  154. package/dist/cli/website-plugins.test.d.ts.map +1 -0
  155. package/dist/cli/website-plugins.test.js +34 -0
  156. package/dist/cli/website-plugins.test.js.map +1 -0
  157. package/dist/orchestrator/plugins/chrome-devtools/config.d.ts.map +1 -1
  158. package/dist/orchestrator/plugins/chrome-devtools/config.js +11 -1
  159. package/dist/orchestrator/plugins/chrome-devtools/config.js.map +1 -1
  160. package/dist/orchestrator/plugins/contentful/config.d.ts.map +1 -1
  161. package/dist/orchestrator/plugins/contentful/config.js +11 -1
  162. package/dist/orchestrator/plugins/contentful/config.js.map +1 -1
  163. package/dist/orchestrator/plugins/convex/config.d.ts.map +1 -1
  164. package/dist/orchestrator/plugins/convex/config.js +11 -1
  165. package/dist/orchestrator/plugins/convex/config.js.map +1 -1
  166. package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -1
  167. package/dist/orchestrator/plugins/coolify/config.js +14 -1
  168. package/dist/orchestrator/plugins/coolify/config.js.map +1 -1
  169. package/dist/orchestrator/plugins/figma/config.d.ts.map +1 -1
  170. package/dist/orchestrator/plugins/figma/config.js +24 -13
  171. package/dist/orchestrator/plugins/figma/config.js.map +1 -1
  172. package/dist/orchestrator/plugins/linear/config.d.ts.map +1 -1
  173. package/dist/orchestrator/plugins/linear/config.js +27 -17
  174. package/dist/orchestrator/plugins/linear/config.js.map +1 -1
  175. package/dist/orchestrator/plugins/netlify/config.d.ts.map +1 -1
  176. package/dist/orchestrator/plugins/netlify/config.js +23 -9
  177. package/dist/orchestrator/plugins/netlify/config.js.map +1 -1
  178. package/dist/orchestrator/plugins/nextjs/config.d.ts.map +1 -1
  179. package/dist/orchestrator/plugins/nextjs/config.js +11 -1
  180. package/dist/orchestrator/plugins/nextjs/config.js.map +1 -1
  181. package/dist/orchestrator/plugins/nx/config.d.ts.map +1 -1
  182. package/dist/orchestrator/plugins/nx/config.js +11 -1
  183. package/dist/orchestrator/plugins/nx/config.js.map +1 -1
  184. package/dist/orchestrator/plugins/pins.test.d.ts +2 -0
  185. package/dist/orchestrator/plugins/pins.test.d.ts.map +1 -0
  186. package/dist/orchestrator/plugins/pins.test.js +78 -0
  187. package/dist/orchestrator/plugins/pins.test.js.map +1 -0
  188. package/dist/orchestrator/plugins/playwright/config.d.ts.map +1 -1
  189. package/dist/orchestrator/plugins/playwright/config.js +11 -1
  190. package/dist/orchestrator/plugins/playwright/config.js.map +1 -1
  191. package/dist/orchestrator/plugins/prisma/config.d.ts.map +1 -1
  192. package/dist/orchestrator/plugins/prisma/config.js +17 -2
  193. package/dist/orchestrator/plugins/prisma/config.js.map +1 -1
  194. package/dist/orchestrator/plugins/resend/config.d.ts.map +1 -1
  195. package/dist/orchestrator/plugins/resend/config.js +17 -1
  196. package/dist/orchestrator/plugins/resend/config.js.map +1 -1
  197. package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -1
  198. package/dist/orchestrator/plugins/sentry/config.js +13 -1
  199. package/dist/orchestrator/plugins/sentry/config.js.map +1 -1
  200. package/dist/orchestrator/plugins/slack/config.d.ts.map +1 -1
  201. package/dist/orchestrator/plugins/slack/config.js +20 -1
  202. package/dist/orchestrator/plugins/slack/config.js.map +1 -1
  203. package/dist/orchestrator/plugins/strapi/config.d.ts.map +1 -1
  204. package/dist/orchestrator/plugins/strapi/config.js +11 -1
  205. package/dist/orchestrator/plugins/strapi/config.js.map +1 -1
  206. package/dist/orchestrator/plugins/trello/config.d.ts.map +1 -1
  207. package/dist/orchestrator/plugins/trello/config.js +21 -1
  208. package/dist/orchestrator/plugins/trello/config.js.map +1 -1
  209. package/dist/orchestrator/plugins/types.d.ts +22 -0
  210. package/dist/orchestrator/plugins/types.d.ts.map +1 -1
  211. package/package.json +3 -1
  212. package/src/cli/adapters/rules-dir-base.ts +23 -44
  213. package/src/cli/adapters/single-file-base.ts +43 -46
  214. package/src/cli/adapters/vscode.ts +28 -71
  215. package/src/cli/baseline.ts +289 -0
  216. package/src/cli/bootstrap.ts +1 -1
  217. package/src/cli/ci.ts +289 -0
  218. package/src/cli/dispatcher.test.ts +2 -2
  219. package/src/cli/docs-accuracy.test.ts +5 -0
  220. package/src/cli/doctor.ts +92 -6
  221. package/src/cli/explain.ts +210 -0
  222. package/src/cli/fleet.ts +176 -0
  223. package/src/cli/github-report.test.ts +158 -0
  224. package/src/cli/github-report.ts +179 -0
  225. package/src/cli/init.test.ts +27 -27
  226. package/src/cli/init.ts +135 -93
  227. package/src/cli/layers.test.ts +525 -0
  228. package/src/cli/layers.ts +1089 -0
  229. package/src/cli/lock.ts +395 -0
  230. package/src/cli/mcp-audit.test.ts +259 -0
  231. package/src/cli/mcp-audit.ts +619 -0
  232. package/src/cli/mcp-upgrade.test.ts +135 -0
  233. package/src/cli/mcp.ts +373 -34
  234. package/src/cli/policy.ts +207 -0
  235. package/src/cli/publish-workflow.test.ts +60 -1
  236. package/src/cli/remove.ts +8 -2
  237. package/src/cli/review.ts +457 -0
  238. package/src/cli/status.test.ts +5 -3
  239. package/src/cli/status.ts +29 -4
  240. package/src/cli/sync-check.test.ts +16 -8
  241. package/src/cli/sync-check.ts +245 -14
  242. package/src/cli/sync.ts +2 -0
  243. package/src/cli/team-ci.test.ts +195 -0
  244. package/src/cli/team-commands.test.ts +253 -0
  245. package/src/cli/team-config.ts +289 -0
  246. package/src/cli/team-health.ts +234 -0
  247. package/src/cli/team-sources.test.ts +578 -0
  248. package/src/cli/types.ts +19 -1
  249. package/src/cli/update.ts +217 -44
  250. package/src/cli/version-range.ts +150 -0
  251. package/src/cli/website-plugins.test.ts +41 -0
  252. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  253. package/src/orchestrator/customizations/README.md +1 -1
  254. package/src/orchestrator/plugins/chrome-devtools/SKILL.md +1 -1
  255. package/src/orchestrator/plugins/chrome-devtools/config.ts +11 -1
  256. package/src/orchestrator/plugins/contentful/SKILL.md +1 -1
  257. package/src/orchestrator/plugins/contentful/config.ts +11 -1
  258. package/src/orchestrator/plugins/convex/SKILL.md +1 -1
  259. package/src/orchestrator/plugins/convex/config.ts +11 -1
  260. package/src/orchestrator/plugins/coolify/config.ts +14 -1
  261. package/src/orchestrator/plugins/cypress/SKILL.md +1 -1
  262. package/src/orchestrator/plugins/figma/SKILL.md +18 -14
  263. package/src/orchestrator/plugins/figma/config.ts +24 -13
  264. package/src/orchestrator/plugins/jira/SKILL.md +2 -2
  265. package/src/orchestrator/plugins/linear/SKILL.md +6 -14
  266. package/src/orchestrator/plugins/linear/config.ts +27 -17
  267. package/src/orchestrator/plugins/netlify/SKILL.md +1 -1
  268. package/src/orchestrator/plugins/netlify/config.ts +23 -9
  269. package/src/orchestrator/plugins/nextjs/config.ts +11 -1
  270. package/src/orchestrator/plugins/nx/config.ts +11 -1
  271. package/src/orchestrator/plugins/pins.test.ts +80 -0
  272. package/src/orchestrator/plugins/playwright/SKILL.md +1 -1
  273. package/src/orchestrator/plugins/playwright/config.ts +11 -1
  274. package/src/orchestrator/plugins/prisma/SKILL.md +1 -1
  275. package/src/orchestrator/plugins/prisma/config.ts +17 -2
  276. package/src/orchestrator/plugins/resend/config.ts +17 -1
  277. package/src/orchestrator/plugins/sanity/SKILL.md +1 -1
  278. package/src/orchestrator/plugins/sentry/config.ts +13 -1
  279. package/src/orchestrator/plugins/slack/config.ts +20 -1
  280. package/src/orchestrator/plugins/strapi/SKILL.md +1 -1
  281. package/src/orchestrator/plugins/strapi/config.ts +11 -1
  282. package/src/orchestrator/plugins/supabase/SKILL.md +1 -1
  283. package/src/orchestrator/plugins/trello/SKILL.md +1 -1
  284. package/src/orchestrator/plugins/trello/config.ts +21 -1
  285. package/src/orchestrator/plugins/types.ts +24 -0
  286. package/src/orchestrator/plugins/vercel/SKILL.md +1 -1
  287. package/src/orchestrator/plugins/vitest/SKILL.md +1 -1
  288. package/src/orchestrator/skill-config-links.test.ts +30 -0
  289. package/src/orchestrator/skills/git-workflow/SKILL.md +1 -1
@@ -0,0 +1,525 @@
1
+ /**
2
+ * Team sources: `.opencastle/config.json`, the baselines it extends, and the
3
+ * merged content every adapter compiles.
4
+ *
5
+ * These are the rules a platform team relies on when it hands a standard to
6
+ * fifty repositories: later layers override earlier ones, a repository cannot
7
+ * quietly drop or replace what the baseline requires, policy only tightens, and
8
+ * a baseline is found exactly where the package manager put it.
9
+ */
10
+ import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync, readdirSync, symlinkSync } from 'node:fs'
11
+ import { tmpdir } from 'node:os'
12
+ import { join, resolve, dirname } from 'node:path'
13
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
14
+ import { resolveSources, materialize, usesTeamSources, requiredEnvVars, hasErrors } from './layers.js'
15
+ import { parseTeamConfig, stripJsonc, TeamConfigSchema } from './team-config.js'
16
+ import { satisfies } from './version-range.js'
17
+ import { findInlineSecret } from './policy.js'
18
+ import { buildLock, serializeLock } from './lock.js'
19
+ import type { StackConfig } from './types.js'
20
+
21
+ const pkgRoot = resolve(import.meta.dirname, '..', '..')
22
+ const noTools: StackConfig = { ides: ['claude-code'], techTools: [], teamTools: [] }
23
+
24
+ function write(root: string, files: Record<string, string>): void {
25
+ for (const [rel, text] of Object.entries(files)) {
26
+ const abs = join(root, rel)
27
+ mkdirSync(dirname(abs), { recursive: true })
28
+ writeFileSync(abs, text)
29
+ }
30
+ }
31
+
32
+ /** A baseline installed where npm would put it. */
33
+ function baseline(project: string, name: string, version: string, files: Record<string, string>, pkg: Record<string, unknown> = {}): void {
34
+ const dir = join(project, 'node_modules', ...name.split('/'))
35
+ write(dir, {
36
+ 'package.json': JSON.stringify({ name, version, opencastle: { baseline: 'layer' }, ...pkg }),
37
+ ...Object.fromEntries(Object.entries(files).map(([k, v]) => [`layer/${k}`, v])),
38
+ })
39
+ }
40
+
41
+ const skill = (name: string, description = `${name} does a thing. Use when it matters.`): string =>
42
+ `---\nname: ${name}\ndescription: "${description}"\n---\n\n# ${name}\n`
43
+
44
+ describe('version ranges', () => {
45
+ it('reads the ranges npm users write', () => {
46
+ expect(satisfies('0.36.2', '^0.36.0')).toBe(true)
47
+ expect(satisfies('0.37.0', '^0.36.0')).toBe(false)
48
+ expect(satisfies('1.4.0', '^1.2.0')).toBe(true)
49
+ expect(satisfies('2.0.0', '^1.2.0')).toBe(false)
50
+ expect(satisfies('0.36.9', '~0.36.1')).toBe(true)
51
+ expect(satisfies('0.37.0', '~0.36.1')).toBe(false)
52
+ expect(satisfies('0.36.4', '0.36.x')).toBe(true)
53
+ expect(satisfies('0.36.0', '>=0.35.0 <0.37.0')).toBe(true)
54
+ expect(satisfies('0.36.0', '>= 0.37.0')).toBe(false)
55
+ expect(satisfies('0.36.0', '0.35.0 || 0.36.0')).toBe(true)
56
+ expect(satisfies('0.36.0', '*')).toBe(true)
57
+ })
58
+
59
+ it('keeps prereleases out of ranges that do not name them', () => {
60
+ expect(satisfies('0.37.0-rc.1', '^0.36.0')).toBe(false)
61
+ expect(satisfies('0.37.0-rc.2', '>=0.37.0-rc.1')).toBe(true)
62
+ })
63
+
64
+ it('says so when it cannot read a range, instead of guessing', () => {
65
+ expect(satisfies('0.36.0', 'latest')).toBeNull()
66
+ })
67
+ })
68
+
69
+ describe('the config file', () => {
70
+ it('accepts comments and trailing commas, as an editor with $schema writes them', () => {
71
+ const text = `{
72
+ // the org standard
73
+ "extends": ["@acme/base",], /* pinned in package.json */
74
+ "exclude": ["skills/seo-patterns"],
75
+ }`
76
+ const { config, issues } = parseTeamConfig(text, 'x')
77
+ expect(issues).toEqual([])
78
+ expect(config).toEqual({ extends: ['@acme/base'], exclude: ['skills/seo-patterns'] })
79
+ })
80
+
81
+ it('leaves comment-like text inside strings alone', () => {
82
+ expect(JSON.parse(stripJsonc('{"url": "https://a.dev/x//y", "s": "a, }"}'))).toEqual({ url: 'https://a.dev/x//y', s: 'a, }' })
83
+ })
84
+
85
+ it('names an unknown setting and suggests the one meant', () => {
86
+ const { config, issues } = parseTeamConfig('{ "extend": ["@acme/base"] }', '.opencastle/config.json')
87
+ expect(config).toBeNull()
88
+ expect(issues[0].message).toContain('unknown setting "extend"')
89
+ expect(issues[0].fix).toContain('"extends"')
90
+ })
91
+
92
+ it('rejects an exclude that names no kind', () => {
93
+ const { issues } = parseTeamConfig('{ "exclude": ["seo-patterns"] }', 'x')
94
+ expect(issues[0].message).toMatch(/must name a kind/)
95
+ })
96
+
97
+ it('matches the published JSON schema, key for key', () => {
98
+ const schema = JSON.parse(readFileSync(join(pkgRoot, 'website', 'public', 'schema', 'config.json'), 'utf8'))
99
+ expect(Object.keys(schema.properties).sort()).toEqual(Object.keys(TeamConfigSchema.entries).sort())
100
+ const policy = TeamConfigSchema.entries.policy.wrapped.entries
101
+ expect(Object.keys(schema.properties.policy.properties).sort()).toEqual(Object.keys(policy).sort())
102
+ expect(Object.keys(schema.properties.policy.properties.mcp.properties).sort()).toEqual(
103
+ Object.keys(policy.mcp.wrapped.entries).sort(),
104
+ )
105
+ const server = TeamConfigSchema.entries.mcpServers.wrapped.value.entries
106
+ expect(Object.keys(schema.properties.mcpServers.additionalProperties.properties).sort()).toEqual(Object.keys(server).sort())
107
+ })
108
+ })
109
+
110
+ describe('credentials written into a server entry', () => {
111
+ it('finds real token formats and secret-named values, and says where — never what', () => {
112
+ expect(findInlineSecret({ env: { STRIPE_KEY: 'sk_live_abcdefghijklmnop1234' } })).toBe('env.STRIPE_KEY')
113
+ expect(findInlineSecret({ headers: { Authorization: 'Bearer ghp_abcdefghijklmnopqrstuvwxyz0123456789' } })).toBe('headers.Authorization')
114
+ expect(findInlineSecret({ env: { API_TOKEN: 'a8f3k2j9d0s7x6c5v4b3' } })).toBe('env.API_TOKEN')
115
+ expect(findInlineSecret({ command: 'npx', args: ['-y', 'srv@1.0.0', '--api-key=a8f3k2j9d0s7x6c5v4b3'] })).toBe('args')
116
+ expect(findInlineSecret({ url: 'https://x.dev/mcp?token=a8f3k2j9d0s7x6c5v4b3' })).toBe('url')
117
+ expect(findInlineSecret({ command: ['npx', '-y', 'srv@1.0.0', '--token', 'glpat-abcdefghijklmnopqrst'] })).toBe('args')
118
+ })
119
+
120
+ it('leaves references, placeholders and ordinary values alone', () => {
121
+ expect(findInlineSecret({ env: { API_TOKEN: '${API_TOKEN}' } })).toBeNull()
122
+ expect(findInlineSecret({ env: { API_TOKEN: '${env:API_TOKEN}' } })).toBeNull()
123
+ expect(findInlineSecret({ environment: { API_TOKEN: '{env:API_TOKEN}' } })).toBeNull()
124
+ expect(findInlineSecret({ headers: { Authorization: 'Bearer ${input:token}' } })).toBeNull()
125
+ expect(findInlineSecret({ env: { API_TOKEN: 'REPLACE_ME' } })).toBeNull()
126
+ expect(findInlineSecret({ env: { LOG_LEVEL: 'debug', PORT: '3000' } })).toBeNull()
127
+ expect(findInlineSecret({ env: { AUTH_URL: 'https://auth.example.com/oauth2/v1' } })).toBeNull()
128
+ expect(findInlineSecret({ command: 'npx', args: ['-y', '@acme/db-mcp@2.1.0'] })).toBeNull()
129
+ })
130
+ })
131
+
132
+ describe('resolving layers', () => {
133
+ let project: string
134
+ beforeEach(() => {
135
+ project = mkdtempSync(join(tmpdir(), 'layers-'))
136
+ })
137
+ afterEach(() => {
138
+ rmSync(project, { recursive: true, force: true })
139
+ })
140
+
141
+ const resolveHere = (stack: StackConfig = noTools) => resolveSources({ pkgRoot, projectRoot: project, stack })
142
+
143
+ it('is OpenCastle alone when the project has no team sources', () => {
144
+ const r = resolveHere()
145
+ expect(r.issues).toEqual([])
146
+ expect(usesTeamSources(r)).toBe(false)
147
+ expect([...r.items.values()].every((i) => i.layer === 'opencastle')).toBe(true)
148
+ })
149
+
150
+ it("adds the project's own content, and records what it replaces", () => {
151
+ write(project, {
152
+ '.opencastle/skills/deploy/SKILL.md': skill('deploy'),
153
+ '.opencastle/skills/testing-workflow/SKILL.md': skill('testing-workflow', 'Our testing rules. Use when writing tests.'),
154
+ '.opencastle/instructions/house-style.md': '# House style\n',
155
+ '.opencastle/agents/release-captain.agent.md': '---\nname: Release captain\ndescription: "Cuts releases"\n---\n\n# RC\n',
156
+ // Not an agent: the directory also holds OpenCastle's own registry.
157
+ '.opencastle/agents/agent-registry.md': '# registry\n',
158
+ })
159
+ const r = resolveHere()
160
+ expect(r.items.get('skills/deploy')?.layer).toBe('project')
161
+ expect(r.items.get('skills/testing-workflow')).toMatchObject({ layer: 'project', overrides: 'opencastle' })
162
+ expect(r.items.get('instructions/house-style')?.layer).toBe('project')
163
+ expect(r.items.get('agents/release-captain')?.layer).toBe('project')
164
+ expect(r.items.has('agents/agent-registry')).toBe(false)
165
+ expect(usesTeamSources(r)).toBe(true)
166
+ })
167
+
168
+ it('finds a baseline where the package manager installed it, below the project', () => {
169
+ baseline(project, '@acme/base', '1.4.0', {
170
+ 'skills/secure-coding/SKILL.md': skill('secure-coding'),
171
+ 'skills/deploy/SKILL.md': skill('deploy', 'The org default.'),
172
+ })
173
+ write(project, {
174
+ '.opencastle/config.json': '{ "extends": ["@acme/base"] }',
175
+ '.opencastle/skills/deploy/SKILL.md': skill('deploy', 'This repo overrides it.'),
176
+ })
177
+ const r = resolveHere()
178
+ expect(r.issues).toEqual([])
179
+ expect(r.layers.map((l) => l.id)).toEqual(['opencastle', '@acme/base', 'project'])
180
+ expect(r.layers[1].version).toBe('1.4.0')
181
+ expect(r.items.get('skills/secure-coding')?.layer).toBe('@acme/base')
182
+ expect(r.items.get('skills/deploy')).toMatchObject({ layer: 'project', overrides: '@acme/base' })
183
+ })
184
+
185
+ it('refuses a baseline that is not installed, a versioned spec, an absolute path, or a package that is not a baseline', () => {
186
+ write(project, { 'node_modules/plain/package.json': JSON.stringify({ name: 'plain', version: '1.0.0' }) })
187
+ write(project, {
188
+ '.opencastle/config.json': JSON.stringify({ extends: ['@acme/missing', '@acme/base@2.0.0', '/abs/path', 'plain'] }),
189
+ })
190
+ const r = resolveHere()
191
+ const messages = r.issues.map((i) => i.message).join('\n')
192
+ expect(messages).toContain('"@acme/missing", which is not installed')
193
+ expect(messages).toContain('version belongs in package.json')
194
+ expect(messages).toContain('an absolute path')
195
+ expect(messages).toContain('"plain", which is not an OpenCastle baseline')
196
+ expect(hasErrors(r)).toBe(true)
197
+ })
198
+
199
+ it('reads a baseline from a path, and loads a diamond once and a cycle not at all', () => {
200
+ write(project, {
201
+ 'shared/a/config.json': '{ "extends": ["../c"] }',
202
+ 'shared/a/skills/a/SKILL.md': skill('a'),
203
+ 'shared/b/config.json': '{ "extends": ["../c"] }',
204
+ 'shared/c/skills/c/SKILL.md': skill('c'),
205
+ '.opencastle/config.json': '{ "extends": ["../shared/a", "../shared/b"] }',
206
+ })
207
+ const r = resolveHere()
208
+ expect(r.issues).toEqual([])
209
+ expect(r.layers.map((l) => l.id)).toEqual(['opencastle', 'shared/c', 'shared/a', 'shared/b', 'project'])
210
+
211
+ write(project, { 'shared/c/config.json': '{ "extends": ["../a"] }' })
212
+ const cyclic = resolveHere()
213
+ expect(cyclic.issues.some((i) => /cycle/.test(i.message))).toBe(true)
214
+ })
215
+
216
+ it('excludes from the layers below, and warns about an exclude that matches nothing', () => {
217
+ write(project, { '.opencastle/config.json': '{ "exclude": ["skills/testing-workflow", "skills/no-such-skill"] }' })
218
+ const r = resolveHere()
219
+ expect(r.items.has('skills/testing-workflow')).toBe(false)
220
+ expect(r.excluded).toEqual([{ ref: 'skills/testing-workflow', by: 'project', from: 'opencastle' }])
221
+ expect(r.issues).toEqual([expect.objectContaining({ level: 'warning', message: expect.stringContaining('skills/no-such-skill') })])
222
+ })
223
+
224
+ it('does not call an exclude of something the stack already left out a mistake', () => {
225
+ write(project, { '.opencastle/config.json': '{ "exclude": ["agents/content-engineer"] }' })
226
+ expect(resolveHere().issues).toEqual([])
227
+ })
228
+
229
+ it('refuses to drop or replace what a baseline requires', () => {
230
+ baseline(project, '@acme/base', '1.0.0', {
231
+ 'config.json': '{ "policy": { "require": ["skills/secure-coding", "instructions/security"] } }',
232
+ 'skills/secure-coding/SKILL.md': skill('secure-coding'),
233
+ 'instructions/security.md': '# Security\n',
234
+ })
235
+ write(project, {
236
+ '.opencastle/config.json': '{ "extends": ["@acme/base"], "exclude": ["instructions/security"] }',
237
+ '.opencastle/skills/secure-coding/SKILL.md': skill('secure-coding', 'A weaker local copy.'),
238
+ })
239
+ const errors = resolveHere().issues.filter((i) => i.level === 'error').map((i) => i.message)
240
+ expect(errors).toContain('excludes instructions/security, which @acme/base requires')
241
+ expect(errors).toContain('project replaces skills/secure-coding (from @acme/base), which @acme/base requires unchanged')
242
+ })
243
+
244
+ it('holds MCP servers to the policy: allowlist, hosts, pinning, and credentials', () => {
245
+ baseline(project, '@acme/base', '1.0.0', {
246
+ 'config.json': JSON.stringify({
247
+ policy: { mcp: { allow: ['acme-*', 'docs', 'Linear'], remoteHosts: ['*.acme.dev', 'mcp.linear.app'], requirePinned: true } },
248
+ }),
249
+ })
250
+ write(project, {
251
+ '.opencastle/config.json': JSON.stringify({
252
+ extends: ['@acme/base'],
253
+ policy: { mcp: { requirePinned: false } },
254
+ mcpServers: {
255
+ 'acme-db': { command: 'npx', args: ['-y', '@acme/db-mcp@2.1.0'], env: { DB_URL: '${DB_URL}' } },
256
+ 'acme-loose': { command: 'npx', args: ['-y', '@acme/loose-mcp'] },
257
+ docs: { url: 'https://docs.example.com/mcp' },
258
+ rogue: { command: 'node', args: ['tools/mcp.js'] },
259
+ 'acme-leak': { url: 'https://x.acme.dev/mcp', headers: { Authorization: 'Bearer ghp_abcdefghijklmnopqrstuvwxyz0123456789' } },
260
+ },
261
+ }),
262
+ })
263
+ const r = resolveHere({ ides: ['claude-code'], techTools: [], teamTools: ['linear', 'slack'] })
264
+ const errors = r.issues.filter((i) => i.level === 'error').map((i) => i.message)
265
+ const warnings = r.issues.filter((i) => i.level === 'warning').map((i) => i.message)
266
+ expect(errors.some((m) => m.includes('"acme-loose" runs @acme/loose-mcp without an exact version'))).toBe(true)
267
+ // The host alone: a URL can carry a credential in its query string.
268
+ expect(errors.some((m) => m.includes('"docs" connects to docs.example.com, a host @acme/base does not allow'))).toBe(true)
269
+ expect(errors.some((m) => m.includes('"rogue", which @acme/base does not allow'))).toBe(true)
270
+ expect(errors.some((m) => m.includes('"acme-leak" has a credential written into headers.Authorization'))).toBe(true)
271
+ expect(errors.some((m) => m.includes('acme-db'))).toBe(false)
272
+ expect(warnings.some((m) => m.includes('a layer can tighten policy, not relax it'))).toBe(true)
273
+ // An integration the policy refuses is left out, not an error.
274
+ expect(r.blocked.get('Slack')).toContain('allowlist')
275
+ expect(r.blocked.has('Linear')).toBe(false)
276
+ })
277
+
278
+ it('leaves out an integration whose remote host the policy does not allow', () => {
279
+ baseline(project, '@acme/base', '1.0.0', { 'config.json': JSON.stringify({ policy: { mcp: { remoteHosts: ['*.acme.dev'] } } }) })
280
+ write(project, { '.opencastle/config.json': '{ "extends": ["@acme/base"] }' })
281
+ const r = resolveHere({ ides: ['claude-code'], techTools: [], teamTools: ['linear'] })
282
+ expect(r.blocked.get('Linear')).toBe('mcp.linear.app is not an allowed host for @acme/base')
283
+ })
284
+
285
+ it('narrows an allowlist from above, and says so when a layer tries to widen one', () => {
286
+ baseline(project, '@acme/base', '1.0.0', { 'config.json': JSON.stringify({ policy: { mcp: { allow: ['Linear', 'Sentry'] } } }) })
287
+ write(project, { '.opencastle/config.json': JSON.stringify({ extends: ['@acme/base'], policy: { mcp: { allow: ['Linear', 'rogue'] } } }) })
288
+ const r = resolveHere({ ides: ['claude-code'], techTools: ['sentry'], teamTools: ['linear'] })
289
+ expect(r.issues.map((i) => i.message)).toContain('allows MCP server "rogue", but @acme/base does not — the stricter list applies')
290
+ // On both lists: kept. On the baseline's only: the project narrowed it out.
291
+ expect(r.blocked.has('Linear')).toBe(false)
292
+ expect(r.blocked.get('Sentry')).toContain('project')
293
+ })
294
+
295
+ it('refuses to compile with an OpenCastle the project did not ask for', () => {
296
+ write(project, { '.opencastle/config.json': '{ "opencastle": "^99.0.0" }' })
297
+ expect(resolveHere().issues[0].message).toMatch(/needs OpenCastle \^99\.0\.0; this is/)
298
+ })
299
+
300
+ it('lists the variables the written servers need: team servers in, refused integrations out', () => {
301
+ write(project, {
302
+ '.opencastle/config.json': JSON.stringify({
303
+ policy: { mcp: { allow: ['acme-db', 'Linear'] } },
304
+ mcpServers: { 'acme-db': { command: 'npx', args: ['-y', '@acme/db-mcp@2.1.0'], env: { DB_URL: '${DB_URL}' } } },
305
+ }),
306
+ })
307
+ const stack: StackConfig = { ides: ['claude-code'], techTools: ['sentry'], teamTools: ['linear'] }
308
+ const vars = requiredEnvVars(resolveHere(stack), stack).map((v) => v.envVar)
309
+ expect(vars).toContain('DB_URL')
310
+ expect(vars).not.toContain('SENTRY_ACCESS_TOKEN')
311
+ })
312
+ })
313
+
314
+ describe('the merged source and the lock', () => {
315
+ let project: string
316
+ beforeEach(() => {
317
+ project = mkdtempSync(join(tmpdir(), 'layers-lock-'))
318
+ })
319
+ afterEach(() => {
320
+ rmSync(project, { recursive: true, force: true })
321
+ })
322
+
323
+ it('normalises team files the way every target needs them', () => {
324
+ write(project, {
325
+ '.opencastle/instructions/security.md': '# Security\r\n\r\nNo secrets.\r\n',
326
+ '.opencastle/agents/rc.agent.md': '# Release captain\n',
327
+ })
328
+ const src = materialize(resolveSources({ pkgRoot, projectRoot: project, stack: noTools }), pkgRoot)
329
+ try {
330
+ const instruction = readFileSync(join(src.root, 'instructions', 'security.instructions.md'), 'utf8')
331
+ expect(instruction).toBe("---\napplyTo: '**'\n---\n\n# Security\n\nNo secrets.\n")
332
+ expect(readFileSync(join(src.root, 'agents', 'rc.agent.md'), 'utf8')).toMatch(/^---\nname: 'rc'\n---/)
333
+ } finally {
334
+ src.dispose()
335
+ }
336
+ expect(existsSync(src.root)).toBe(false)
337
+ })
338
+
339
+ it('ships an integration skill as its SKILL.md alone', () => {
340
+ const stack: StackConfig = { ides: ['claude-code'], techTools: ['sentry'], teamTools: [] }
341
+ const src = materialize(resolveSources({ pkgRoot, projectRoot: project, stack }), pkgRoot)
342
+ try {
343
+ expect(readdirSync(join(src.root, 'skills', 'sentry'))).toEqual(['SKILL.md'])
344
+ } finally {
345
+ src.dispose()
346
+ }
347
+ })
348
+
349
+ it('is deterministic and carries no machine-specific paths', () => {
350
+ baseline(project, '@acme/base', '1.4.0', { 'skills/secure-coding/SKILL.md': skill('secure-coding') })
351
+ write(project, {
352
+ '.opencastle/config.json': JSON.stringify({
353
+ extends: ['@acme/base'],
354
+ exclude: ['skills/seo-patterns'],
355
+ mcpServers: { 'acme-db': { command: 'npx', args: ['-y', '@acme/db-mcp@2.1.0'], env: { DB_URL: '${DB_URL}' } } },
356
+ }),
357
+ })
358
+ const lockOnce = (): string => {
359
+ const src = materialize(resolveSources({ pkgRoot, projectRoot: project, stack: noTools }), pkgRoot)
360
+ try {
361
+ return serializeLock(buildLock(src, { ides: ['cursor', 'claude-code'], stack: noTools }))
362
+ } finally {
363
+ src.dispose()
364
+ }
365
+ }
366
+ const a = lockOnce()
367
+ expect(lockOnce()).toBe(a)
368
+ expect(a).not.toContain(project)
369
+ expect(a).not.toContain(tmpdir())
370
+ const lock = JSON.parse(a)
371
+ expect(lock.targets).toEqual(['claude-code', 'cursor'])
372
+ expect(lock.layers.map((l: { id: string }) => l.id)).toEqual(['opencastle', '@acme/base', 'project'])
373
+ expect(lock.content['skills/secure-coding'].from).toBe('@acme/base')
374
+ expect(lock.excluded).toEqual({ 'skills/seo-patterns': 'project' })
375
+ expect(lock.mcp['acme-db']).toMatchObject({ from: 'project', transport: 'stdio', launch: 'npx -y @acme/db-mcp@2.1.0', env: ['DB_URL'] })
376
+ expect(lock.mcp['acme-db'].sha).toMatch(/^[0-9a-f]{12}$/)
377
+ expect(lock.context.tokens).toBeGreaterThan(0)
378
+ })
379
+ })
380
+
381
+ describe('what review found, kept fixed', () => {
382
+ let project: string
383
+ beforeEach(() => {
384
+ project = mkdtempSync(join(tmpdir(), 'layers-review-'))
385
+ })
386
+ afterEach(() => {
387
+ rmSync(project, { recursive: true, force: true })
388
+ })
389
+ const resolveHere = (stack: StackConfig = noTools) => resolveSources({ pkgRoot, projectRoot: project, stack })
390
+ const lockOf = (stack: StackConfig = noTools): string => {
391
+ const src = materialize(resolveHere(stack), pkgRoot)
392
+ try {
393
+ return serializeLock(buildLock(src, { ides: ['claude-code'], stack }))
394
+ } finally {
395
+ src.dispose()
396
+ }
397
+ }
398
+
399
+ it('a required item the project provides — rather than replaces — satisfies the requirement', () => {
400
+ baseline(project, '@acme/base', '1.0.0', { 'config.json': '{ "policy": { "require": ["instructions/security", "skills/testing-workflow"] } }' })
401
+ write(project, {
402
+ '.opencastle/config.json': '{ "extends": ["@acme/base"] }',
403
+ '.opencastle/instructions/security.md': '# Security\n',
404
+ '.opencastle/skills/testing-workflow/SKILL.md': skill('testing-workflow'),
405
+ })
406
+ const errors = resolveHere().issues.filter((i) => i.level === 'error').map((i) => i.message)
407
+ // Provided where nothing existed: fine. Replacing OpenCastle's own: named as OpenCastle's.
408
+ expect(errors).toEqual(['project replaces skills/testing-workflow (from OpenCastle), which @acme/base requires unchanged'])
409
+ })
410
+
411
+ it('lets a project opt out of a server a baseline defines, by exclude or by its own allowlist', () => {
412
+ baseline(project, '@acme/base', '1.0.0', {
413
+ 'config.json': JSON.stringify({ mcpServers: { 'acme-tools': { url: 'https://tools.acme.dev/mcp' }, 'acme-docs': { url: 'https://docs.acme.dev/mcp' } } }),
414
+ })
415
+ write(project, {
416
+ '.opencastle/config.json': JSON.stringify({ extends: ['@acme/base'], exclude: ['mcpServers/acme-tools'], policy: { mcp: { allow: ['Linear'] } } }),
417
+ })
418
+ const r = resolveHere()
419
+ expect(r.issues.filter((i) => i.level === 'error')).toEqual([])
420
+ expect(r.servers.size).toBe(0)
421
+ expect(r.blocked.get('acme-tools')).toBe('excluded by project')
422
+ expect(r.blocked.get('acme-docs')).toBe('not on the MCP allowlist of project')
423
+ })
424
+
425
+ it('passes editor variables through, and does not list them as environment variables', () => {
426
+ write(project, {
427
+ '.opencastle/config.json': JSON.stringify({
428
+ mcpServers: { local: { command: 'node', args: ['${workspaceFolder}/tools/mcp.js'], env: { TOKEN: '${API_TOKEN}' } } },
429
+ }),
430
+ })
431
+ const vars = requiredEnvVars(resolveHere(), noTools).map((v) => v.envVar)
432
+ expect(vars).toEqual(['API_TOKEN'])
433
+ })
434
+
435
+ it('lists a variable two servers share once', () => {
436
+ write(project, {
437
+ '.opencastle/config.json': JSON.stringify({
438
+ mcpServers: {
439
+ a: { url: 'https://a.dev/mcp', headers: { Authorization: 'Bearer ${ACME_TOKEN}' } },
440
+ b: { url: 'https://b.dev/mcp', headers: { Authorization: 'Bearer ${ACME_TOKEN}' } },
441
+ },
442
+ }),
443
+ })
444
+ const vars = requiredEnvVars(resolveHere(), noTools)
445
+ expect(vars.filter((v) => v.envVar === 'ACME_TOKEN')).toHaveLength(1)
446
+ })
447
+
448
+ it('gives Copilot applyTo on an instruction whose frontmatter has none', () => {
449
+ write(project, { '.opencastle/instructions/rule.md': '---\ndescription: a rule\n---\n\n# Rule\n' })
450
+ const src = materialize(resolveHere(), pkgRoot)
451
+ try {
452
+ expect(readFileSync(join(src.root, 'instructions', 'rule.instructions.md'), 'utf8')).toBe("---\ndescription: a rule\napplyTo: '**'\n---\n\n# Rule\n")
453
+ } finally {
454
+ src.dispose()
455
+ }
456
+ })
457
+
458
+ it('makes the same lock whatever the OS left beside the content or did to line endings', () => {
459
+ write(project, {
460
+ 'shared/skills/s/SKILL.md': skill('s'),
461
+ 'shared/skills/s/notes.txt': 'one\ntwo\n',
462
+ '.opencastle/config.json': '{ "extends": ["../shared"] }',
463
+ '.opencastle/skills/p/SKILL.md': skill('p'),
464
+ })
465
+ const clean = lockOf()
466
+ write(project, {
467
+ 'shared/skills/s/notes.txt': 'one\r\ntwo\r\n',
468
+ 'shared/skills/s/SKILL.md': skill('s').replace(/\n/g, '\r\n'),
469
+ 'shared/skills/.DS_Store': 'junk',
470
+ '.opencastle/skills/p/.DS_Store': 'junk',
471
+ })
472
+ expect(lockOf()).toBe(clean)
473
+ })
474
+
475
+ it('does not follow a link out of the layer', () => {
476
+ const outside = mkdtempSync(join(tmpdir(), 'layers-outside-'))
477
+ try {
478
+ writeFileSync(join(outside, 'secret.txt'), 'not yours')
479
+ write(project, { '.opencastle/skills/s/SKILL.md': skill('s') })
480
+ symlinkSync(join(outside, 'secret.txt'), join(project, '.opencastle', 'skills', 's', 'linked.txt'))
481
+ const src = materialize(resolveHere(), pkgRoot)
482
+ try {
483
+ expect(existsSync(join(src.root, 'skills', 's', 'linked.txt'))).toBe(false)
484
+ } finally {
485
+ src.dispose()
486
+ }
487
+ } finally {
488
+ rmSync(outside, { recursive: true, force: true })
489
+ }
490
+ })
491
+
492
+ it('warns about a baseline kept in a directory git ignores', () => {
493
+ write(project, {
494
+ '.opencastle/baselines/org/skills/x/SKILL.md': skill('x'),
495
+ '.opencastle/config.json': '{ "extends": ["./baselines/org"] }',
496
+ })
497
+ expect(resolveHere().issues.map((i) => i.message).join('\n')).toContain('which git ignores')
498
+ })
499
+ })
500
+
501
+ describe('credential detection, tuned', () => {
502
+ it('does not stop a compile over identifiers, settings or paths', () => {
503
+ expect(findInlineSecret({ env: { OAUTH_CLIENT_ID: 'Iv1.8a61f9b3a7aba766' } })).toBeNull()
504
+ expect(findInlineSecret({ env: { AUTH_MODE: 'oauth2-client-credentials' } })).toBeNull()
505
+ expect(findInlineSecret({ env: { AWS_SECRET_ID: 'prod/app/db-credentials-v2' } })).toBeNull()
506
+ expect(findInlineSecret({ env: { TOKEN_SHA: 'a'.repeat(64).replace(/a/g, (_, i) => String(i % 10)) } })).toBeNull()
507
+ expect(findInlineSecret({ command: 'npx', args: ['-y', 's@1.0.0', '--token-file=secrets/token1.txt'] })).toBeNull()
508
+ })
509
+
510
+ it('leaves keys that are public by design alone, and still catches base64 with a slash', () => {
511
+ expect(findInlineSecret({ env: { STRIPE_PUBLISHABLE_KEY: 'pk_live_51H8abcdefghijklmnop1234' } })).toBeNull()
512
+ expect(findInlineSecret({ env: { RECAPTCHA_SITE_KEY: '6LcX8abcdefghijklmnop1234' } })).toBeNull()
513
+ expect(findInlineSecret({ headers: { 'Idempotency-Key': '3f2b8c1e-9a7d-4e5f-8b6a-1c2d3e4f5a6b' } })).toBeNull()
514
+ expect(findInlineSecret({ env: { AWS_SECRET_ACCESS_KEY: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY1' } })).toBe('env.AWS_SECRET_ACCESS_KEY')
515
+ })
516
+
517
+ it('catches the formats and shapes it used to miss', () => {
518
+ expect(findInlineSecret({ env: { ANYTHING: 'npm_' + 'a1B2c3D4e5'.repeat(3) + 'a1B2c3' } })).toBe('env.ANYTHING')
519
+ expect(findInlineSecret({ env: { OPENAI_KEY: 'q8w7e6r5t4y3u2i1o0p9' } })).toBe('env.OPENAI_KEY')
520
+ expect(findInlineSecret({ command: 'npx', args: ['-y', 's@1.0.0', '--key', 'q8w7e6r5t4y3u2i1o0p9'] })).toBe('args')
521
+ expect(findInlineSecret({ env: { DATABASE_URL: 'postgres://app:hunter2@db.internal/app' } })).toBe('env.DATABASE_URL')
522
+ expect(findInlineSecret({ headers: { Authorization: 'Basic dXNlcjpwYXNz' } })).toBe('headers.Authorization')
523
+ expect(findInlineSecret({ env: { DB_PASSWORD: 'x9$Kq2mZ7vLp4wN8' } })).toBe('env.DB_PASSWORD')
524
+ })
525
+ })