Skip to content

feat: embed specHash from spec-metadata.json in published package#91

Merged
jwulf merged 4 commits intomainfrom
feat/embed-spec-hash
Apr 1, 2026
Merged

feat: embed specHash from spec-metadata.json in published package#91
jwulf merged 4 commits intomainfrom
feat/embed-spec-hash

Conversation

@jwulf
Copy link
Copy Markdown
Member

@jwulf jwulf commented Mar 31, 2026

Summary

Embeds the specHash from spec-metadata.json as an exported constant in the published npm package.

Changes

  • New hook: hooks/post/050-emit-spec-hash.ts — reads specHash from external-spec/bundled/spec-metadata.json and writes src/gen/specHash.ts
  • Export: SPEC_HASH re-exported from src/index.ts → included in dist/
  • Unit test: tests/spec-hash.test.ts — verifies non-empty string with sha256: prefix

Usage

import { SPEC_HASH } from '@camunda8/orchestration-cluster-api';
console.log(SPEC_HASH); // "sha256:da0eafa2..."

Verification

  • npm run build passes
  • SPEC_HASH accessible via both ESM and CJS imports
  • Test verifies format: /^sha256:[0-9a-f]{64}$/

Closes #90

Add post-gen hook (050-emit-spec-hash.ts) that reads specHash from
spec-metadata.json and writes src/gen/specHash.ts with an exported
SPEC_HASH constant. This constant is re-exported from src/index.ts
and included in the dist/ output.

Consumers can import { SPEC_HASH } to audit which API spec version
was used to generate a given SDK release.

Closes #90
Copilot AI review requested due to automatic review settings March 31, 2026 23:59
@jwulf jwulf requested a review from emilyoram April 1, 2026 00:02
Add post-gen hook (050-emit-spec-hash.ts) that reads specHash from
spec-metadata.json and writes src/gen/specHash.ts with an exported
SPEC_HASH constant. This constant is re-exported from src/index.ts
and included in the dist/ output.

Consumers can import { SPEC_HASH } to audit which API spec version
was used to generate a given SDK release.

Closes #90
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR embeds the bundled OpenAPI specHash into the generated SDK output and re-exports it from the package entrypoint so consumers can audit which upstream spec a published SDK build was generated from.

Changes:

  • Added a post-generation hook to emit src/gen/specHash.ts from external-spec/bundled/spec-metadata.json.
  • Re-exported SPEC_HASH from src/index.ts so it’s included in dist/.
  • Added a Vitest unit test validating the exported hash format.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
hooks/post/050-emit-spec-hash.ts New post-hook that reads specHash from spec metadata and writes src/gen/specHash.ts.
src/gen/specHash.ts Generated constant file exporting SPEC_HASH.
src/index.ts Re-exports SPEC_HASH from the package entrypoint.
tests/spec-hash.test.ts Unit test asserting SPEC_HASH is present and matches the expected sha256 format.

Comment on lines +18 to +23
const metadata = JSON.parse(fs.readFileSync(METADATA_PATH, 'utf8'));
const specHash: string = metadata.specHash ?? '';

if (!specHash.startsWith('sha256:')) {
console.warn(`[emit-spec-hash] Unexpected specHash format: ${specHash}`);
}
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook defaults specHash to '' and only warns on unexpected formats, but still writes SPEC_HASH. That can result in publishing an empty/invalid hash (or failing tests later) without a clear failure cause. Consider validating against the expected /^sha256:[0-9a-f]{64}$/ and aborting (non-zero exit) if specHash is missing or invalid.

Copilot uses AI. Check for mistakes.
jwulf and others added 2 commits April 1, 2026 15:52
- Fail fast (throw) when spec-metadata.json is missing instead of skipping
- Validate specHash against /^sha256:[0-9a-f]{64}$/ and abort if invalid
- Use JSON.stringify for safe string literal emission
- Remove duplicate SPEC_HASH export in src/index.ts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jwulf jwulf self-assigned this Apr 1, 2026
@jwulf jwulf merged commit 0c0adc5 into main Apr 1, 2026
4 checks passed
@jwulf jwulf deleted the feat/embed-spec-hash branch April 1, 2026 03:15
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Released in v8.9.0-alpha.25 (npm: @camunda8/orchestration-cluster-api@8.9.0-alpha.25).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Embed specHash from spec-metadata.json in generated output and published package

2 participants