Skip to content

Commit 9dfda15

Browse files
committed
chore(pkg): publish runtime only; relocate tests; add publint + verifier
The published package was shipping 25 test files and 5 dev scripts: the `files` allowlist listed `src/` and `scripts/` wholesale, and with a `files` field present npm ignores `.npmignore` entirely — so its test/dev excludes silently did nothing. Packaging (industry-standard allowlist, no .npmignore): - Relocate tests src/tests/ -> top-level test/ so the `src` allowlist entry no longer pulls them in. Rewrite their `../` imports to `../src/` and fix bug-fixes.test.js path anchors (srcDir/projectDir) for the new depth. - Tighten `files` to a precise allowlist (src, mcp.json, .env.example, README, LICENSE, CLAUDE.md, AGENTS.md) and delete the dead `.npmignore`. Tarball: 61 -> 31 files, 0 tests, 0 dev scripts. - Add publint (npm run lint:package) and a prepublishOnly gate that runs the offline suites + publint before publish (omits the live integration test so publishing never hits a real site). Dev tooling: - Add scripts/verify-tool-names.mjs: cross-checks every gf_/gv_ name in the server instructions, docs and demo against the tools the server actually registers (gv_* are generated from the live abilities catalog and can drift). Run via npm run verify:tool-names against a live site. - Document packaging and the verifier in AGENTS.md. Verified: full test:all incl. live integration green; npm pack --dry-run clean (31 files); publint passes; verify:tool-names passes.
1 parent bda10bb commit 9dfda15

30 files changed

Lines changed: 280 additions & 129 deletions

‎.npmignore‎

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎AGENTS.md‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,25 @@ MCP/
3838
│ │ ├── validators.js # Domain-specific validators (forms, entries, feeds, etc.)
3939
│ │ ├── field-validation.js # FieldAwareValidator for field-specific rules
4040
│ │ └── test-config.js # Dual test/live environment config, TestFormManager
41-
│ ├── utils/
42-
│ │ ├── compact.js # stripEmpty() — recursive null/empty/false stripping for token optimization
43-
│ │ ├── logger.js # MCP-safe logger (stderr in MCP mode, console in test)
44-
│ │ └── sanitize.js # Credential masking for safe logging
45-
│ └── tests/
46-
│ ├── run.js # Test runner
47-
│ ├── helpers.js # Mock data generators, test utilities
48-
│ ├── integration.test.js # Live API integration tests
49-
│ ├── server-tools.test.js # Tool registration validation
50-
│ ├── forms.test.js # Forms endpoint tests
51-
│ ├── entries.test.js # Entries endpoint tests
52-
│ ├── feeds.test.js # Feeds endpoint tests
53-
│ ├── submissions.test.js # Submission pipeline tests
54-
│ ├── authentication.test.js # Auth method tests
55-
│ ├── validation.test.js # Input validation tests
56-
│ ├── field-validation.test.js # Field-specific validation
57-
│ ├── field-manager.test.js # FieldManager unit tests
58-
│ ├── field-dependencies.test.js # DependencyTracker tests
59-
│ ├── field-positioner.test.js # PositionEngine tests
60-
│ ├── field-registry.test.js # Field registry tests
61-
│ ├── field-operations-e2e.test.js # Field operations E2E
62-
│ ├── field-operations-integration.test.js # Field ops integration
63-
│ ├── compact.test.js # stripEmpty compact utility tests
64-
│ └── sanitize.test.js # Sanitization tests
41+
│ └── utils/
42+
│ ├── compact.js # stripEmpty() — recursive null/empty/false stripping for token optimization
43+
│ ├── logger.js # MCP-safe logger (stderr in MCP mode, console in test)
44+
│ └── sanitize.js # Credential masking for safe logging
45+
├── test/ # Test suites — top-level, NOT published (see Packaging)
46+
│ ├── run.js # Custom test runner (npm run test:unit)
47+
│ ├── helpers.js # Mock data generators, test utilities
48+
│ ├── integration.test.js # Live API integration tests (npm test)
49+
│ ├── views.test.js, views-stress.test.js # GravityView inspector + abilities coverage
50+
│ ├── abilities-loader.test.js # Abilities catalog → gv_* tool generation
51+
│ └── *.test.js # forms, entries, feeds, fields, validation, submissions, compact, sanitize, …
6552
├── scripts/
6653
│ ├── check-env.js # Environment validation script
6754
│ ├── setup-test-data.js # Test data seeding
6855
│ ├── test-field-ops.js # Field operations smoke test
6956
│ ├── test-server-output.js # Server output verification
70-
│ └── verify-field-tools.js # Field tool registration check
57+
│ ├── verify-field-tools.js # Field tool registration check
58+
│ ├── verify-tool-names.mjs # Cross-check doc/instruction tool names vs registered tools (dev-only, not published)
59+
│ └── stress-abilities.mjs # Synthetic abilities-loader stress/contract test
7160
└── .github/workflows/
7261
├── publish.yml # npm publish workflow
7362
├── security.yml # Security scanning
@@ -245,7 +234,7 @@ All delete operations (`deleteForm`, `deleteEntry`, `deleteFeed`) check `this.al
245234
return wrapHandler(() => gravityFormsClient.newToolMethod(params))();
246235
```
247236

248-
5. **Add tests** — create test in `src/tests/` following existing patterns (see `forms.test.js` for reference).
237+
5. **Add tests** — create test in `test/` following existing patterns (see `forms.test.js` for reference). Import source under test as `../src/…`.
249238

250239
### Adding a New Field Type to the Registry
251240

@@ -340,7 +329,7 @@ npm run test:all # Run everything sequentially
340329
npm test # Integration tests (requires live API)
341330
```
342331

343-
Tests use a custom runner (`src/tests/run.js`), not Jest/Mocha. Test helpers in `src/tests/helpers.js` provide mock data generators (`generateMockForm`, `generateMockEntry`, `generateMockFeed`).
332+
Tests use a custom runner (`test/run.js`), not Jest/Mocha. Test helpers in `test/helpers.js` provide mock data generators (`generateMockForm`, `generateMockEntry`, `generateMockFeed`).
344333

345334
For integration tests, set `GRAVITY_FORMS_TEST_*` env vars pointing to a test WordPress site. Test forms are prefixed with `TEST_` and auto-cleaned via `TestFormManager`.
346335

@@ -374,6 +363,15 @@ No build step — pure ESM JavaScript, runs directly with `node src/index.js`. R
374363

375364
12. **Test mode resolves env vars at client construction.** When `GRAVITYKIT_MCP_TEST_MODE=true` (or legacy `GRAVITYMCP_TEST_MODE=true`), `testConfig.resolveEnv()` remaps `GRAVITY_FORMS_TEST_BASE_URL` → `GRAVITY_FORMS_BASE_URL` (and consumer key/secret). The rest of the client and AuthManager work unchanged. — `config/test-config.js:60-95`, `gravity-forms-client.js:16`
376365

366+
## Packaging
367+
368+
What ships to npm is governed solely by the **`files` allowlist** in `package.json` — there is intentionally **no `.npmignore`** (with a `files` field present npm ignores it, so keeping one is misleading). Allowlist, not denylist: a new file ships only if it matches `files`.
369+
370+
- **Ships:** `src/` (runtime), `mcp.json`, `.env.example`, `README.md`, `LICENSE`, `CLAUDE.md`, `AGENTS.md`.
371+
- **Excluded by omission:** `test/` (tests are top-level, not under `src/`), `scripts/` (dev tooling), `.github/`, `package-lock.json`.
372+
- **`npm run lint:package`** runs [publint](https://publint.dev) to validate package correctness; **`prepublishOnly`** runs the offline test suites + publint, so a broken or mis-packaged build can't be published. It deliberately omits the live integration test (`npm test`) to avoid hitting a real site during publish.
373+
- **Verify before publishing:** `npm pack --dry-run` lists exactly what will ship.
374+
377375
## Releasing
378376

379377
**Every version tag MUST include a CHANGELOG.md update.** Follow this checklist:
@@ -388,6 +386,8 @@ No build step — pure ESM JavaScript, runs directly with `node src/index.js`. R
388386

389387
Skipping any step (especially CHANGELOG) will leave the release history incomplete for future developers and AI agents.
390388

389+
**Before tagging, run `npm run verify:tool-names` against a live site.** The `gv_*` tools are generated from the installed GravityView/Foundation Abilities catalog, so a catalog rename can silently leave the server `instructions` string, README, or the demo referencing tools that no longer exist. The script cross-checks every `gf_`/`gv_` name in prose against what the server actually registers and exits non-zero on a mismatch. Requires WordPress credentials in the environment (see Required Environment). Dev-only — not shipped in the npm package.
390+
391391
## Related Resources
392392

393393
- **CLAUDE.md** — Concise project identity and critical rules

‎package-lock.json‎

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@
1313
"inspect": "npx @modelcontextprotocol/inspector node src/index.js",
1414
"check-env": "node scripts/check-env.js",
1515
"setup-test-data": "node scripts/setup-test-data.js",
16-
"test": "node src/tests/integration.test.js",
17-
"test:unit": "node src/tests/run.js",
18-
"test:field-ops": "node --test src/tests/field-manager.test.js src/tests/field-registry.test.js src/tests/field-dependencies.test.js src/tests/field-positioner.test.js",
19-
"test:auth": "node src/tests/authentication.test.js",
20-
"test:forms": "node src/tests/forms.test.js",
21-
"test:entries": "node src/tests/entries.test.js",
22-
"test:feeds": "node src/tests/feeds.test.js",
23-
"test:submissions": "node src/tests/submissions.test.js",
24-
"test:validation": "node src/tests/validation.test.js",
25-
"test:field-validation": "node src/tests/field-validation.test.js",
26-
"test:tools": "node src/tests/server-tools.test.js",
27-
"test:compact": "node src/tests/compact.test.js",
28-
"test:views": "node src/tests/views.test.js",
16+
"verify:tool-names": "node scripts/verify-tool-names.mjs",
17+
"test": "node test/integration.test.js",
18+
"test:unit": "node test/run.js",
19+
"test:field-ops": "node --test test/field-manager.test.js test/field-registry.test.js test/field-dependencies.test.js test/field-positioner.test.js",
20+
"test:auth": "node test/authentication.test.js",
21+
"test:forms": "node test/forms.test.js",
22+
"test:entries": "node test/entries.test.js",
23+
"test:feeds": "node test/feeds.test.js",
24+
"test:submissions": "node test/submissions.test.js",
25+
"test:validation": "node test/validation.test.js",
26+
"test:field-validation": "node test/field-validation.test.js",
27+
"test:tools": "node test/server-tools.test.js",
28+
"test:compact": "node test/compact.test.js",
29+
"test:views": "node test/views.test.js",
2930
"test:all": "npm run test:unit && npm run test:field-ops && npm run test:auth && npm run test:forms && npm run test:entries && npm run test:feeds && npm run test:submissions && npm run test:validation && npm run test:field-validation && npm run test:tools && npm run test:views && npm test",
30-
"test:coverage": "echo 'Running all tests with coverage analysis' && npm run test:all"
31+
"test:coverage": "echo 'Running all tests with coverage analysis' && npm run test:all",
32+
"lint:package": "publint",
33+
"prepublishOnly": "npm run test:unit && npm run test:field-ops && npm run test:field-validation && npm run test:views && publint"
3134
},
3235
"keywords": [
3336
"mcp",
@@ -51,12 +54,12 @@
5154
},
5255
"files": [
5356
"src/",
54-
"scripts/",
55-
"LICENSE",
56-
"README.md",
57-
".env.example",
5857
"mcp.json",
59-
"CLAUDE.md"
58+
".env.example",
59+
"README.md",
60+
"LICENSE",
61+
"CLAUDE.md",
62+
"AGENTS.md"
6063
],
6164
"repository": {
6265
"type": "git",
@@ -95,5 +98,8 @@
9598
"Integration testing",
9699
"Security validation"
97100
]
101+
},
102+
"devDependencies": {
103+
"publint": "^0.3.21"
98104
}
99105
}

0 commit comments

Comments
 (0)