-
-
Notifications
You must be signed in to change notification settings - Fork 39.2k
Expand file tree
/
Copy pathnpm-publish-surface.test.js
More file actions
269 lines (249 loc) · 8.21 KB
/
Copy pathnpm-publish-surface.test.js
File metadata and controls
269 lines (249 loc) · 8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**
* Tests for the npm publish surface contract.
*/
const assert = require("assert")
const fs = require("fs")
const path = require("path")
const { spawnSync } = require("child_process")
const { getNpmPackEntry } = require("../lib/npm-pack-output")
function runTest(name, fn) {
try {
fn()
console.log(` ✓ ${name}`)
return true
} catch (error) {
console.log(` ✗ ${name}`)
console.error(` ${error.message}`)
return false
}
}
function normalizePublishPath(value) {
return String(value).replace(/\\/g, "/").replace(/\/$/, "")
}
function isCoveredByAncestor(target, roots) {
const parts = target.split("/")
for (let index = 1; index < parts.length; index += 1) {
const ancestor = parts.slice(0, index).join("/")
if (roots.has(ancestor)) {
return true
}
}
return false
}
function buildExpectedPublishPaths(repoRoot) {
const modules = JSON.parse(
fs.readFileSync(path.join(repoRoot, "manifests", "install-modules.json"), "utf8")
).modules
const extraPaths = [
"manifests",
"scripts/ecc.js",
"scripts/feedback.js",
"scripts/catalog.js",
"scripts/ci/scan-supply-chain-iocs.js",
"scripts/ci/supply-chain-advisory-sources.js",
"scripts/consult.js",
"scripts/profile.js",
"scripts/control-pane.js",
"scripts/dashboard-web.js",
"scripts/discussion-audit.js",
"scripts/doctor.js",
"scripts/status.js",
"scripts/sessions-cli.js",
"scripts/work-items.js",
"scripts/install-apply.js",
"scripts/install-guided.js",
"scripts/install-plan.js",
"scripts/ito.js",
"scripts/list-installed.js",
"scripts/loop-status.js",
"scripts/memory.js",
"scripts/memory-mcp.mjs",
"scripts/nasiko.js",
"scripts/observability-readiness.js",
"scripts/plan-canvas.js",
"scripts/operator-readiness-dashboard.js",
"scripts/platform-audit.js",
"scripts/preview-pack-smoke.js",
"scripts/release-approval-gate.js",
"scripts/release-video-suite.js",
"scripts/skill-create-output.js",
"scripts/repair.js",
"scripts/harness-adapter-compliance.js",
"scripts/session-inspect.js",
"scripts/setup.js",
"scripts/uninstall.js",
"scripts/welcome.js",
"scripts/gemini-adapt-agents.js",
"scripts/sync-ecc-to-codex.sh",
"scripts/codex/legacy-sync-state.js",
"scripts/codex/install-global-git-hooks.sh",
"scripts/codex/check-codex-global-state.sh",
"scripts/codex-git-hooks",
"scripts/codex/check-plugin-cache.js",
"scripts/codex/merge-codex-config.js",
"scripts/codex/merge-mcp-config.js",
".codex-plugin",
"plugins/ecc",
".mcp.json",
"install.sh",
"install.ps1",
"schemas",
"agent.yaml",
".github/PULL_REQUEST_TEMPLATE.md",
"COMMANDS-QUICK-REF.md",
"CONTRIBUTING.md",
"VERSION",
"assets/ecc-icon.svg",
"assets/hero.png",
"assets/images/community",
"docs/CODEX-NAVIGATION-GUIDE.md",
"docs/COMMAND-AGENT-MAP.md",
"docs/design/ecc-memory-vault.md",
"docs/design/context-profiles.md",
"assets/images/sponsors",
]
const exclusionPaths = [
"!**/__pycache__/**",
"!**/*.pyc",
"!**/*.pyo",
"!**/*.pyd",
"!**/.pytest_cache/**",
]
const combined = new Set(
[...modules.flatMap((module) => module.paths || []), ...extraPaths, ...exclusionPaths].map(normalizePublishPath)
)
return [...combined]
.filter((publishPath) => !isCoveredByAncestor(publishPath, combined))
.sort()
}
function main() {
console.log("\n=== Testing npm publish surface ===\n")
let passed = 0
let failed = 0
const repoRoot = path.join(__dirname, "..", "..")
const packageJson = JSON.parse(
fs.readFileSync(path.join(repoRoot, "package.json"), "utf8")
)
const expectedPublishPaths = buildExpectedPublishPaths(repoRoot)
const actualPublishPaths = packageJson.files.map(normalizePublishPath).sort()
const tests = [
["package.json files align to the module graph and explicit runtime allowlist", () => {
assert.deepStrictEqual(actualPublishPaths, expectedPublishPaths)
}],
["npm pack publishes the reduced runtime surface", () => {
const result = spawnSync("npm", ["pack", "--dry-run", "--json"], {
cwd: repoRoot,
encoding: "utf8",
shell: process.platform === "win32",
})
assert.strictEqual(result.status, 0, result.error?.message || result.stderr)
const packOutput = JSON.parse(result.stdout)
const packEntry = getNpmPackEntry(packOutput, packageJson.name)
const packagedPaths = new Set(packEntry?.files?.map((file) => file.path) ?? [])
for (const requiredPath of [
"scripts/catalog.js",
"scripts/ci/scan-supply-chain-iocs.js",
"scripts/ci/supply-chain-advisory-sources.js",
"scripts/consult.js",
"scripts/profile.js",
"scripts/lib/context-profiles.js",
"scripts/lib/context-pack-registry.js",
"scripts/lib/context-profile-support.js",
"schemas/context-profile.schema.json",
"schemas/context-pack-registry.schema.json",
"manifests/context-profiles/lean@1.json",
"manifests/context-profiles/full@1.json",
"manifests/context-packs/skill-registry@1.json",
"docs/design/context-profiles.md",
"scripts/control-pane.js",
"scripts/feedback.js",
"scripts/ito.js",
"scripts/memory.js",
"scripts/memory-mcp.mjs",
"scripts/nasiko.js",
"scripts/lib/nasiko-release.js",
"scripts/lib/memory-vault-format.js",
"scripts/lib/memory-vault.js",
"scripts/discussion-audit.js",
"scripts/operator-readiness-dashboard.js",
"scripts/preview-pack-smoke.js",
"scripts/release-approval-gate.js",
"scripts/release-video-suite.js",
"scripts/work-items.js",
"scripts/platform-audit.js",
"scripts/sync-ecc-to-codex.sh",
"scripts/codex/legacy-sync-state.js",
"scripts/codex/install-global-git-hooks.sh",
"scripts/codex/check-codex-global-state.sh",
"scripts/codex-git-hooks/pre-commit",
"scripts/codex-git-hooks/pre-push",
"scripts/setup.js",
"scripts/codex/check-plugin-cache.js",
".gemini/GEMINI.md",
".qwen/QWEN.md",
".claude-plugin/plugin.json",
".github/PULL_REQUEST_TEMPLATE.md",
".codex-plugin/plugin.json",
".agents/skills/unified-memory/SKILL.md",
".agents/skills/unified-memory/agents/openai.yaml",
".cursor/skills/unified-memory/SKILL.md",
"COMMANDS-QUICK-REF.md",
"CONTRIBUTING.md",
"plugins/ecc/.codex-plugin/plugin.json",
"assets/ecc-icon.svg",
"assets/hero.png",
"assets/images/community/discord.svg",
"assets/images/community/heart.svg",
"docs/CODEX-NAVIGATION-GUIDE.md",
"docs/COMMAND-AGENT-MAP.md",
"docs/design/ecc-memory-vault.md",
"schemas/install-state.schema.json",
"schemas/memory.schema.json",
"skills/backend-patterns/SKILL.md",
"skills/skill-comply/SKILL.md",
"skills/unified-memory/SKILL.md",
]) {
assert.ok(
packagedPaths.has(requiredPath),
`npm pack should include ${requiredPath}`
)
}
for (const excludedPath of [
"contexts/dev.md",
"examples/CLAUDE.md",
"plugins/README.md",
"scripts/ci/catalog.js",
]) {
assert.ok(
!packagedPaths.has(excludedPath),
`npm pack should not include ${excludedPath}`
)
}
for (const packagedPath of packagedPaths) {
assert.ok(
!packagedPath.includes("__pycache__/"),
`npm pack should not include Python bytecode cache path ${packagedPath}`
)
assert.ok(
!/\.py[cod]$/.test(packagedPath),
`npm pack should not include Python bytecode file ${packagedPath}`
)
assert.ok(
!packagedPath.includes(".pytest_cache/"),
`npm pack should not include pytest cache path ${packagedPath}`
)
}
}],
]
for (const [name, fn] of tests) {
if (runTest(name, fn)) {
passed += 1
} else {
failed += 1
}
}
console.log(`\nPassed: ${passed}`)
console.log(`Failed: ${failed}`)
process.exit(failed > 0 ? 1 : 0)
}
main()