Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dist/guarded-write-contract.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/guarded-write-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ export function revokeKnowledgePrivateInputDescriptor(descriptor: KnowledgePriva
state.revoked = true;
}

/** @internal */
export function materializeKnowledgePrivateInput(
descriptor: KnowledgePrivateInputDescriptor,
): KnowledgeGuardedPayload {
Expand Down
21 changes: 21 additions & 0 deletions tests/package-release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)), '..');
Expand Down Expand Up @@ -43,6 +44,13 @@ const forbiddenPackagePaths = [
'scripts/validate-public-package.mjs',
].sort();

const rootRuntimeExports = builtPackageRoot as Record<string, unknown>;

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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true,
"stripInternal": true,
"outDir": "./dist",
"rootDir": "./src"
},
Expand Down
Loading