@norskvideo/ctl-dev-kit 0.1.66 → 0.1.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -238,6 +238,9 @@ export interface CanonicalBytes {
238
238
  flake: string;
239
239
  upgradeLatest: string;
240
240
  syncDevKit: string;
241
+ /** conventions/sync-ctl-packages.yml — the ctl-* pin freshness PR. No per-repo
242
+ * line at all, so it is verbatim and sync-drift creates it where absent. */
243
+ syncCtlPackages: string;
241
244
  publishDocs: string;
242
245
  /** conventions/build-docs.yml — the embedded docs variant (bundle -> image, no upload). */
243
246
  buildDocs: string;
@@ -513,6 +516,14 @@ export function checkDrift(repoRoot: string, canonical: CanonicalBytes, opts: Ch
513
516
  );
514
517
  }
515
518
 
519
+ // sync-ctl-packages.yml is OPTIONAL until a repo has been synced once — it is
520
+ // NEW, and sync-drift creates it. Unlike its neighbours it carries no per-repo
521
+ // line (it dispatches to no dashboard), so the whole file is canonical.
522
+ const syncCtlPath = join(repoRoot, ".github", "workflows", "sync-ctl-packages.yml");
523
+ if (existsSync(syncCtlPath) && readFileSync(syncCtlPath, "utf8") !== canonical.syncCtlPackages) {
524
+ push(`.github/workflows/sync-ctl-packages.yml differs from conventions/sync-ctl-packages.yml. ${RESYNC}`);
525
+ }
526
+
516
527
  // smoke.yml is OPTIONAL until every product carries a tests/smoke.spec.ts
517
528
  // (04b s7.2 sequences the required-file rule last). When present it is the
518
529
  // shared, single-sourced workflow; only its `product:` dispatch key and the
@@ -569,6 +580,7 @@ if (import.meta.main) {
569
580
  flake: readFileSync(join(import.meta.dir, "..", "build", "flake.nix"), "utf8"),
570
581
  upgradeLatest: readFileSync(join(import.meta.dir, "upgrade-latest.yml"), "utf8"),
571
582
  syncDevKit: readFileSync(join(import.meta.dir, "sync-dev-kit.yml"), "utf8"),
583
+ syncCtlPackages: readFileSync(join(import.meta.dir, "sync-ctl-packages.yml"), "utf8"),
572
584
  publishDocs: readFileSync(join(import.meta.dir, "publish-docs.yml"), "utf8"),
573
585
  buildDocs: readFileSync(join(import.meta.dir, "build-docs.yml"), "utf8"),
574
586
  checks: readFileSync(join(import.meta.dir, "checks.yml"), "utf8"),
@@ -0,0 +1,162 @@
1
+ # Keep this product fresh against the ctl-* npm family: the test harness that
2
+ # drives its smoke and integration tiers, the SDK, the foundation helpers and
3
+ # the product-template schema.
4
+ #
5
+ # sync-dev-kit already does this for the conventions package, and upgrade-latest
6
+ # does it for the Norsk nightly line. Nothing did it for the rest, so the pins
7
+ # drifted silently: on 2026-08-30 studio carried a conventions pin bumped that
8
+ # morning beside an SDK three releases behind, and three repos ran three
9
+ # different vintages of the same smoke runner. The caret ranges admit the new
10
+ # versions -- `--frozen-lockfile` is what holds them back, and nothing ever
11
+ # regenerated the lockfile.
12
+ #
13
+ # Unlike sync-dev-kit this NEVER pushes to main. Its gate is drift + lint +
14
+ # typecheck + unit, and a bump to the test harness changes the code that drives
15
+ # smoke and integration -- neither of which that gate runs, because both need
16
+ # Docker and a licence. A green gate therefore proves strictly less here than it
17
+ # does for a conventions bump, so the bump goes to a human as a PR. A red gate
18
+ # still opens one, as a draft: adopting a breaking change is real engineering,
19
+ # not a copy-paste, and the PR is where that work belongs.
20
+ #
21
+ # Single-sourced in @norskvideo/ctl-dev-kit (conventions/sync-ctl-packages.yml)
22
+ # and copied verbatim into each product repo; the check:drift gate fails CI if a
23
+ # copy diverges. Never hand-edit the copy -- edit the source and re-sync.
24
+ name: sync-ctl-packages
25
+
26
+ on:
27
+ schedule:
28
+ # Clear of sync-dev-kit's 04:37 so the two never race the same lockfile.
29
+ - cron: "52 4 * * *"
30
+ workflow_dispatch:
31
+
32
+ permissions:
33
+ contents: write
34
+ pull-requests: write
35
+
36
+ concurrency:
37
+ group: sync-ctl-packages-${{ github.ref }}
38
+ cancel-in-progress: true
39
+
40
+ jobs:
41
+ sync:
42
+ runs-on: x64
43
+ steps:
44
+ # CI_DISPATCH_TOKEN, not the automatic GITHUB_TOKEN: a PR opened by
45
+ # GITHUB_TOKEN raises no workflow runs, so the product's own build, smoke
46
+ # and integration would never execute against the new pins -- which is the
47
+ # entire reason for opening it. clean: false for the same reason as the
48
+ # other shared jobs: the suites leave root-owned bind-mount dirs under
49
+ # test-temp/ that a non-root git clean cannot remove.
50
+ - uses: actions/checkout@v5
51
+ with:
52
+ token: ${{ secrets.CI_DISPATCH_TOKEN }}
53
+ clean: false
54
+
55
+ - name: Resolve the newest published ctl-* packages and rewrite the pins
56
+ id: bump
57
+ run: |
58
+ set -euo pipefail
59
+ reg="https://registry.npmjs.org"
60
+ # The conventions package is deliberately absent: sync-dev-kit owns it,
61
+ # lands it straight to main, and re-syncs the copied files with it.
62
+ family="ctl-test-harness ctl-sdk ctl-foundation ctl-product-template-schema"
63
+
64
+ # Every tracked package.json, not just the root: a repo can pin the
65
+ # same package in a nested workspace (playout pins the harness twice),
66
+ # and a root-only rewrite would split the line across the two.
67
+ mapfile -t manifests < <(git ls-files '*package.json' ':!:**/node_modules/**')
68
+
69
+ moved=""
70
+ for short in $family; do
71
+ pkg="@norskvideo/$short"
72
+ enc="@norskvideo%2F$short"
73
+ # The runner has no npm; read the dist-tag off the registry with
74
+ # curl+jq, as sync-dev-kit and upgrade-latest both do.
75
+ new="$(curl -fsSL --retry 3 --retry-all-errors --retry-delay 2 "$reg/$enc" | jq -r '."dist-tags".latest')"
76
+ [ -n "$new" ] && [ "$new" != "null" ] || { echo "could not resolve $pkg latest"; exit 1; }
77
+
78
+ for m in "${manifests[@]}"; do
79
+ old="$(grep -oE "\"$pkg\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" "$m" | head -1 | sed -E 's/.*"([^"]*)"$/\1/' || true)"
80
+ # Absent here, or a workspace protocol spec that names no version.
81
+ case "$old" in "" | workspace:*) continue ;; esac
82
+ old_bare="${old#^}"; old_bare="${old_bare#~}"
83
+ [ "$old_bare" != "$new" ] || continue
84
+ # Surgical single-line rewrite so the file keeps its formatting;
85
+ # a jq reserialize would reflow it and trip the formatter.
86
+ sed -i -E "s|(\"$pkg\"[[:space:]]*:[[:space:]]*\")[^\"]*(\")|\1^$new\2|" "$m"
87
+ echo "$m: $pkg $old -> ^$new"
88
+ moved="$moved- \`$pkg\` $old -> \`^$new\` ($m)"$'\n'
89
+ done
90
+ done
91
+
92
+ if [ -z "$moved" ]; then
93
+ echo "every ctl-* pin is already on its newest published version."
94
+ echo "changed=0" >> "$GITHUB_OUTPUT"
95
+ else
96
+ echo "changed=1" >> "$GITHUB_OUTPUT"
97
+ { echo "moved<<PINS"; printf '%s' "$moved"; echo "PINS"; } >> "$GITHUB_OUTPUT"
98
+ fi
99
+
100
+ - name: Reinstall and run the product gate
101
+ id: gate
102
+ if: steps.bump.outputs.changed == '1'
103
+ continue-on-error: true
104
+ run: |
105
+ nix develop .#build --command bash -c '
106
+ set -euo pipefail
107
+ bun install
108
+ bun run check:drift
109
+ bun run lint
110
+ bun run typecheck
111
+ bun run test:unit
112
+ '
113
+
114
+ - name: Open (or update) the pin-freshness PR
115
+ if: steps.bump.outputs.changed == '1'
116
+ env:
117
+ GH_TOKEN: ${{ secrets.CI_DISPATCH_TOKEN }}
118
+ GATE: ${{ steps.gate.outcome }}
119
+ run: |
120
+ set -euo pipefail
121
+ branch="chore/sync-ctl-packages"
122
+ git config user.name "github-actions[bot]"
123
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
124
+ git checkout -B "$branch"
125
+ git add -A
126
+ git commit -m "chore: sync the ctl-* pins to their newest published versions"
127
+ # One branch, force-pushed: a daily schedule must refresh the standing
128
+ # PR rather than accumulate a new one every morning.
129
+ git push -f origin "$branch"
130
+
131
+ if [ "$GATE" = "success" ]; then
132
+ verdict="Gate green: check:drift, lint, typecheck and unit tests all pass on the new pins."
133
+ draft=""
134
+ else
135
+ verdict="**Gate red** — the new pins do not fit this product as-is. Adopting them is real engineering, not a merge."
136
+ draft="--draft"
137
+ fi
138
+
139
+ body="$(cat <<EOF
140
+ Automated by \`sync-ctl-packages\`.
141
+
142
+ ## Pins moved
143
+
144
+ ${{ steps.bump.outputs.moved }}
145
+
146
+ ## What the gate proved
147
+
148
+ $verdict
149
+
150
+ It did **not** run smoke or integration — both need Docker and a licence.
151
+ A test-harness bump changes the code that drives those tiers, so the
152
+ runs raised on this PR are the real evidence. Read them before merging.
153
+ EOF
154
+ )"
155
+
156
+ if [ -z "$(gh pr list --head "$branch" --state open --json number --jq '.[].number')" ]; then
157
+ gh pr create $draft --head "$branch" --base main \
158
+ --title "chore: sync the ctl-* pins to their newest published versions" \
159
+ --body "$body"
160
+ else
161
+ gh pr edit "$branch" --body "$body"
162
+ fi
@@ -223,6 +223,15 @@ export function syncDrift(repoRoot: string, canonical: CanonicalBytes): SyncRepo
223
223
  syncWorkflow(repoRoot, ".github/workflows/checks.yml", canonical.checks, r);
224
224
  syncWorkflow(repoRoot, ".github/workflows/upgrade-latest.yml", canonical.upgradeLatest, r);
225
225
  syncWorkflow(repoRoot, ".github/workflows/sync-dev-kit.yml", canonical.syncDevKit, r);
226
+ // No per-repo line to preserve, so it is written whole -- and CREATED where
227
+ // absent, unlike syncWorkflow's copies. That is how a repo acquires the
228
+ // workflow at all: its next sync run installs it.
229
+ writeIfChanged(
230
+ join(repoRoot, ".github/workflows/sync-ctl-packages.yml"),
231
+ canonical.syncCtlPackages,
232
+ ".github/workflows/sync-ctl-packages.yml",
233
+ r.written,
234
+ );
226
235
  syncBuildImage(repoRoot, canonical.buildImage, r);
227
236
  syncSmoke(repoRoot, canonical.smoke, r);
228
237
 
@@ -256,6 +265,7 @@ if (import.meta.main) {
256
265
  flake: readFileSync(join(dir, "..", "build", "flake.nix"), "utf8"),
257
266
  upgradeLatest: readFileSync(join(dir, "upgrade-latest.yml"), "utf8"),
258
267
  syncDevKit: readFileSync(join(dir, "sync-dev-kit.yml"), "utf8"),
268
+ syncCtlPackages: readFileSync(join(dir, "sync-ctl-packages.yml"), "utf8"),
259
269
  publishDocs: readFileSync(join(dir, "publish-docs.yml"), "utf8"),
260
270
  buildDocs: readFileSync(join(dir, "build-docs.yml"), "utf8"),
261
271
  checks: readFileSync(join(dir, "checks.yml"), "utf8"),
@@ -18,6 +18,7 @@ export interface Canon {
18
18
  flakeLock: string;
19
19
  upgradeLatest: string;
20
20
  syncDevKit: string;
21
+ syncCtlPackages: string;
21
22
  checks: string;
22
23
  biome: string;
23
24
  tsconfigBase: string;
@@ -39,6 +40,7 @@ export function loadCanon(): Canon {
39
40
  flakeLock: readFileSync(join(buildDir, "flake.lock"), "utf8"),
40
41
  upgradeLatest: readFileSync(join(conventionsDir, "upgrade-latest.yml"), "utf8"),
41
42
  syncDevKit: readFileSync(join(conventionsDir, "sync-dev-kit.yml"), "utf8"),
43
+ syncCtlPackages: readFileSync(join(conventionsDir, "sync-ctl-packages.yml"), "utf8"),
42
44
  checks: readFileSync(join(conventionsDir, "checks.yml"), "utf8"),
43
45
  buildDocs: readFileSync(join(conventionsDir, "build-docs.yml"), "utf8"),
44
46
  biome: readFileSync(join(conventionsDir, "biome.base.json"), "utf8"),
@@ -111,6 +111,7 @@ function conventionFiles(ctx: ShapeContext, shape: ShapeModule): GeneratedFile[]
111
111
  { path: ".github/workflows/checks.yml", content: fillProduct(canon.checks) },
112
112
  { path: ".github/workflows/upgrade-latest.yml", content: fillProduct(canon.upgradeLatest) },
113
113
  { path: ".github/workflows/sync-dev-kit.yml", content: fillProduct(canon.syncDevKit) },
114
+ { path: ".github/workflows/sync-ctl-packages.yml", content: canon.syncCtlPackages },
114
115
  { path: ".github/workflows/build-image.yml", content: fillProduct(canon.buildImage) },
115
116
  { path: ".github/actions/ci-status-dispatch/action.yml", content: loadAsset("ci-status-dispatch.yml") },
116
117
  { path: "manifest.seed.json", content: seedJson(ctx) },
@@ -0,0 +1,117 @@
1
+ // Lint a repo's licenceTemplate.json against what the repo actually is.
2
+ //
3
+ // The template is this repo's half of a licence: the `products[]` entries a
4
+ // grant needs in order to entitle it. Minting composes {a grant's header} +
5
+ // {the union of one or more repos' entries}, so a template that names the wrong
6
+ // product — or an imageRef the build never produces — mints a licence that
7
+ // entitles nothing, and the first sign is a 60-second readiness timeout.
8
+ //
9
+ // That is not hypothetical. licensing/partner-all-products-template.json is
10
+ // hand-maintained, names four products, and has silently omitted both turnkeys
11
+ // for as long as they have existed. This lint is what makes the derived
12
+ // version impossible to get wrong the same way.
13
+ //
14
+ // It asserts recorded INTENT matches reality, not security: a user can retag
15
+ // any image, so imageRef buys no defence. What it buys is a statement of what
16
+ // was meant, which is only worth having if something keeps it true.
17
+ import { readFileSync } from "node:fs";
18
+
19
+ export interface RepoFacts {
20
+ /** The repo's own PRODUCT_NAME. */
21
+ product: string;
22
+ /** The image name CI builds under — see builtImageName. */
23
+ image: string;
24
+ }
25
+
26
+ /** The image name CI builds under, by CI's own rule: PUBLISH_IMAGE when set,
27
+ * else the build script's IMAGE_TAG default, tag stripped. The licence matches
28
+ * on the repo part alone (`imageRefMatches`: `parsed.repo !== entry.imageRef`),
29
+ * so the tag never belongs in a template. */
30
+ export function builtImageName(opts: { publishImage: string; buildDefault: string }): string | null {
31
+ const ref = opts.publishImage.trim() || opts.buildDefault.trim();
32
+ if (!ref) return null;
33
+ // Strip a tag, but not a registry port: a colon is a tag only after the last slash.
34
+ const lastSlash = ref.lastIndexOf("/");
35
+ const colon = ref.indexOf(":", lastSlash + 1);
36
+ return colon === -1 ? ref : ref.slice(0, colon);
37
+ }
38
+
39
+ const REQUIRED_ENTRY_FIELDS = ["product", "imageRef", "versionConstraint", "mode"] as const;
40
+
41
+ /** Fields that describe WHO a licence was cut for. A repo does not know them,
42
+ * and a merged staff licence that inherited one repo's expiry would be a
43
+ * quiet, dated surprise. */
44
+ const GRANT_ONLY_FIELDS = ["issuedTo", "email", "expiry", "timeout", "nonProduction"] as const;
45
+
46
+ export function templateProblems(templateJson: string, repo: RepoFacts): string[] {
47
+ let parsed: { products?: unknown } & Record<string, unknown>;
48
+ try {
49
+ parsed = JSON.parse(templateJson);
50
+ } catch (e) {
51
+ return [`licenseTemplate.json is not valid JSON: ${String(e)}`];
52
+ }
53
+ if (typeof parsed !== "object" || parsed === null) return ["licenseTemplate.json is not an object"];
54
+
55
+ const problems: string[] = [];
56
+ for (const f of GRANT_ONLY_FIELDS) {
57
+ if (f in parsed) {
58
+ problems.push(`licenseTemplate.json carries "${f}", which belongs to the grant, not the repo — remove it`);
59
+ }
60
+ }
61
+ if (!Array.isArray(parsed.products)) {
62
+ problems.push('licenseTemplate.json has no "products" array');
63
+ return problems;
64
+ }
65
+
66
+ const entries = parsed.products as Record<string, unknown>[];
67
+ for (const [i, entry] of entries.entries()) {
68
+ for (const f of REQUIRED_ENTRY_FIELDS) {
69
+ if (typeof entry?.[f] !== "string") problems.push(`products[${i}] is missing "${f}"`);
70
+ }
71
+ const ref = entry?.imageRef;
72
+ if (typeof ref === "string") {
73
+ const lastSlash = ref.lastIndexOf("/");
74
+ if (ref.indexOf(":", lastSlash + 1) !== -1) {
75
+ problems.push(`products[${i}].imageRef "${ref}" carries a tag; a licence matches the repo part only`);
76
+ }
77
+ }
78
+ }
79
+
80
+ const named = entries.map((e) => e?.product).filter((p): p is string => typeof p === "string");
81
+ if (!named.includes(repo.product)) {
82
+ problems.push(
83
+ `licenseTemplate.json does not name this repo's product ${repo.product} (names: ${named.join(", ") || "nothing"})`,
84
+ );
85
+ return problems;
86
+ }
87
+
88
+ const mine = entries.find((e) => e?.product === repo.product);
89
+ if (typeof mine?.imageRef === "string" && mine.imageRef !== repo.image) {
90
+ problems.push(`products[].imageRef for ${repo.product} is "${mine.imageRef}" but this repo builds "${repo.image}"`);
91
+ }
92
+ return problems;
93
+ }
94
+
95
+ if (import.meta.main) {
96
+ const [file, product, image] = process.argv.slice(2);
97
+ if (!file || !product || !image) {
98
+ console.error("usage: check-template.ts <licenseTemplate.json> <product-name> <built-image-name>");
99
+ process.exit(2);
100
+ }
101
+ let contents: string;
102
+ try {
103
+ contents = readFileSync(file, "utf8");
104
+ } catch {
105
+ // Absence is not yet an error: the turnkeys' templates wait on their
106
+ // customer-facing image names being settled. Flipping this to a failure is
107
+ // a one-line change once every repo carries one.
108
+ console.log(`licence-template: no ${file} — not yet required in this repo`);
109
+ process.exit(0);
110
+ }
111
+ const problems = templateProblems(contents, { product, image });
112
+ if (problems.length) {
113
+ for (const p of problems) console.error(`licence-template: ${p}`);
114
+ process.exit(1);
115
+ }
116
+ console.log(`licence-template: ${file} names ${product} at ${image}`);
117
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@norskvideo/ctl-dev-kit",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./create-product": "./create-product/create-product.ts",