diff --git a/dist/guarded-write-contract.d.ts b/dist/guarded-write-contract.d.ts index 4c9bcb8..678b69d 100644 --- a/dist/guarded-write-contract.d.ts +++ b/dist/guarded-write-contract.d.ts @@ -291,7 +291,6 @@ export declare function computeKnowledgeGuardedManifestDeterministicKey(maintain export declare function assertKnowledgeGuardedPayload(verb: KnowledgeGuardedWriteVerb, payload: KnowledgeGuardedPayload): void; export declare function createKnowledgePrivateInputDescriptor(options: CreateKnowledgePrivateInputDescriptorOptions): KnowledgePrivateInputDescriptor; export declare function revokeKnowledgePrivateInputDescriptor(descriptor: KnowledgePrivateInputDescriptor): void; -export declare function materializeKnowledgePrivateInput(descriptor: KnowledgePrivateInputDescriptor): KnowledgeGuardedPayload; export declare function assertKnowledgeTerminalCompleteness(reconciliation: KnowledgeTerminalReconciliation, expected: { deterministic_key: string; operation_id: string; diff --git a/src/guarded-write-contract.ts b/src/guarded-write-contract.ts index 8f9af78..a3d78b8 100644 --- a/src/guarded-write-contract.ts +++ b/src/guarded-write-contract.ts @@ -953,6 +953,7 @@ export function revokeKnowledgePrivateInputDescriptor(descriptor: KnowledgePriva state.revoked = true; } +/** @internal */ export function materializeKnowledgePrivateInput( descriptor: KnowledgePrivateInputDescriptor, ): KnowledgeGuardedPayload { diff --git a/tests/package-release.test.ts b/tests/package-release.test.ts index 9926cec..8995d50 100644 --- a/tests/package-release.test.ts +++ b/tests/package-release.test.ts @@ -8,6 +8,7 @@ import { spawnSync } from 'node:child_process'; import { readFileSync } from 'node:fs'; import { dirname, join, posix } from 'node:path'; import { fileURLToPath } from 'node:url'; +import * as builtPackageRoot from '../dist/index.js'; import { budget } from './support/budget'; const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..'); @@ -43,6 +44,13 @@ const forbiddenPackagePaths = [ 'scripts/validate-public-package.mjs', ].sort(); +const rootRuntimeExports = builtPackageRoot as Record; + +function declarationExportsIdentifier(source: string, identifier: string): boolean { + return new RegExp(`\\bexport\\s+(?:declare\\s+)?(?:function|const|class|interface|type)\\s+${identifier}\\b`).test(source) + || new RegExp(`\\bexport\\s*\\{[^}]*\\b${identifier}\\b`, 's').test(source); +} + describe('public package release safety', () => { // Node's builtin list, hardcoded on purpose. `builtinModules` under `bun test` returns BUN's // list, which includes `ws`, `undici` and `bun` - real npm package names that are NOT Node @@ -100,6 +108,19 @@ describe('public package release safety', () => { } }); + test('guarded private-input public declarations match the runtime export contract', () => { + const rootDeclaration = readFileSync(join(repoRoot, 'dist/index.d.ts'), 'utf8'); + const guardedContractDeclaration = readFileSync(join(repoRoot, 'dist/guarded-write-contract.d.ts'), 'utf8'); + + expect(rootRuntimeExports.createKnowledgePrivateInputDescriptor).toBeFunction(); + expect(declarationExportsIdentifier(rootDeclaration, 'createKnowledgePrivateInputDescriptor')).toBe(true); + expect(declarationExportsIdentifier(guardedContractDeclaration, 'createKnowledgePrivateInputDescriptor')).toBe(true); + + expect(rootRuntimeExports.materializeKnowledgePrivateInput).toBeUndefined(); + expect(declarationExportsIdentifier(rootDeclaration, 'materializeKnowledgePrivateInput')).toBe(false); + expect(declarationExportsIdentifier(guardedContractDeclaration, 'materializeKnowledgePrivateInput')).toBe(false); + }); + /** * Imports of a published script that would NOT resolve for someone who installed the * package. Returns the offending specifiers, so both the enforcement test and the tests diff --git a/tsconfig.build.json b/tsconfig.build.json index 30aa799..1335ec5 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -4,6 +4,7 @@ "noEmit": false, "declaration": true, "emitDeclarationOnly": true, + "stripInternal": true, "outDir": "./dist", "rootDir": "./src" },