diff --git a/.changeset/compose-stacks-job-name-across-packages.md b/.changeset/compose-stacks-job-name-across-packages.md new file mode 100644 index 00000000000..131624bd5c4 --- /dev/null +++ b/.changeset/compose-stacks-job-name-across-packages.md @@ -0,0 +1,21 @@ +--- +'@objectstack/spec': minor +--- + +fix(spec)!: composition refuses one job name enabled in two packages of the composed artifact, where the boot would schedule none of them + +Clause-②: no (narrowing) +Metadata-protocol: narrowed +Skills-docs: none — no skill teaches declaring one job name in two packages of a composition; the refusal names every enabled job of the name and prescribes the fix + + + +**BREAKING** accept-set narrowing, shipped as `minor`. + +- **Refused now, at composition (`STACK_CROSS_REFERENCE_INVALID`, 422), once the result carries `packages[]`.** One job name enabled in two package bodies, or in a package body and the residual (a top-level job no body declares: under `composeStacks(stacks, { manifest: 'preserve' })` an input with no `manifest`; under `'first'`, `'last'` or an index any top-level job beside an input that is itself a multi-package artifact). The boot's job binder schedules every job of an artifact by its bare name, whichever package declares it, and refuses a name two enabled jobs share, so none of them was scheduled (`NOT SCHEDULED` at `error`); the install-local door already refused such a package. The finding names every enabled job of the name: `Job 'crm_nightly' is declared enabled twice across the packages of one composed artifact: 'com.example.sales' (stack #0) jobs[0] and 'com.example.billing' (stack #1) jobs[0]. …`, a residual job marked `(the top level, outside every package body)`. +- **Read as the binder reads it.** Enabled jobs only, by name; each job counted once per place it is reached, so one job object that two inputs carry (a built stack shared by two compositions, or passed twice) is two jobs, as the binder binds both; the residual is counted beyond the package bodies' flattened copies, never by content. +- **Also refused now: the residual's own pair beside a body job of that name.** Two residual jobs of one name are the one-package finding (`Job 'NAME' is declared twice in \`jobs\``), as before when no package body carries the name. When a body does carry it, the pair used to be read as that body's copies and composed; it is refused now, with the one-package wording, which counts a disabled job too. So is one job object reached twice in one holder. +- **Unchanged.** A disabled twin composes (a disabled job is scheduled by nothing). A body job's own flattened copy is not a second job. Distinct job names compose. A flat composition (no `packages[]`) is one package and keeps its own finding. +- **Installed artifacts.** An artifact built before this keeps loading; the binder still refuses the name at boot, naming every holder. + +FROM → TO: two packages composed into one artifact each declaring an enabled job `crm_nightly` → rename one of the two jobs, or disable one (`enabled: false`). diff --git a/packages/cloud-connection/src/marketplace-install-local-jobs.test.ts b/packages/cloud-connection/src/marketplace-install-local-jobs.test.ts index b3f97c694b6..14bfe10ccaf 100644 --- a/packages/cloud-connection/src/marketplace-install-local-jobs.test.ts +++ b/packages/cloud-connection/src/marketplace-install-local-jobs.test.ts @@ -572,8 +572,14 @@ describe('[#32572] install-local refuses a package with two enabled jobs of one jobs: [TWIN], } as never); // No `manifest`: its jobs reach the artifact's top level and no package body — the residual. - const host = defineStack({ objects: [{ ...SYNCED, name: 'jobs_app_host_rec', label: 'Host record' }], jobs: [TWIN_SLOW] } as never); + // Composition now refuses a job name enabled in a body and the residual, so this is an artifact it did + // not build (the door's backstop case): the residual's job is composed under a stand-in name, and its + // own name restored in the JSON the door reads. + const STAND_IN = `${TWIN.name}_stand_in`; + const host = defineStack({ objects: [{ ...SYNCED, name: 'jobs_app_host_rec', label: 'Host record' }], jobs: [{ ...TWIN_SLOW, name: STAND_IN }] } as never); const bundle = JSON.parse(JSON.stringify(composeStacks([alpha, host, defineStack(artifact(undefined) as never)] as never[], { manifest: 'preserve' }))); + for (const job of bundle.jobs as Array<{ name: string }>) if (job.name === STAND_IN) job.name = TWIN.name; + expect(bundle.jobs.map((job: { name: string }) => job.name), 'the body job\'s top-level copy and the residual\'s own job').toEqual([TWIN.name, TWIN.name]); const res = await install(bundle); diff --git a/packages/runtime/src/app-artifact-handlers.job-pull.test.ts b/packages/runtime/src/app-artifact-handlers.job-pull.test.ts index 1dc32a3b0c3..ce15b52e794 100644 --- a/packages/runtime/src/app-artifact-handlers.job-pull.test.ts +++ b/packages/runtime/src/app-artifact-handlers.job-pull.test.ts @@ -798,6 +798,30 @@ const beta = defineStack({ /** The artifact as `os build` writes it and a boot reads it back: composed, then through JSON. */ const jsonLoaded = (stacks: unknown[]) => JSON.parse(JSON.stringify(composeStacks(stacks as never[], { manifest: 'preserve' }))) as Record; +/** The stand-in suffix {@link handBuilt} gives each input's job names, and takes back off. */ +const STAND_IN = '__hand_built_'; +/** + * The artifact a build emitted before composition judged a job name enabled in two holders — the binder's + * backstop case, an artifact `composeStacks` did not build. `composeStacks` now refuses that pair, so it is + * composed with each input's job names made unique and the names restored in the JSON a boot reads: the + * layout {@link jsonLoaded} emits (the body copies at the top level, the residual's own jobs beside them), + * name for name. Pinned equal to {@link jsonLoaded} on a composition that still composes, below. + */ +const handBuilt = (stacks: unknown[]) => { + const tagged = stacks.map((stack, i) => { + const plain = JSON.parse(JSON.stringify(stack)) as { jobs?: Array<{ name: string }> }; + if (!Array.isArray(plain.jobs)) return stack; + return defineStack({ ...plain, jobs: plain.jobs.map((job) => ({ ...job, name: `${job.name}${STAND_IN}${i}` })) } as never); + }); + const bundle = jsonLoaded(tagged); + const restore = (jobs: unknown) => { + if (!Array.isArray(jobs)) return; + for (const job of jobs as Array<{ name: string }>) job.name = job.name.replace(new RegExp(`${STAND_IN}\\d+$`), ''); + }; + restore(bundle.jobs); + for (const entry of (bundle.packages ?? []) as Array<{ manifest?: { jobs?: unknown } }>) restore(entry.manifest?.jobs); + return bundle; +}; /** * Schedule `bundle` as `appId` on a real job service (`CronJobAdapter` unless `makeAdapter` says otherwise), then fire every job it holds: @@ -845,12 +869,21 @@ async function scheduleAndRun(bundle: unknown, appId: string, makeAdapter: () => * was pulled as the body before. [#32411] With both jobs enabled the binder now * refuses the name at bind and schedules neither; a run meets the attribution * refusal when the name's twin is disabled (the fail-closed pin below). + * Composition now refuses an ENABLED pair, so an enabled pair here is an artifact it did not build + * ({@link handBuilt}): the binder is the backstop for it. */ describe('[#32355] a job name a package body declares and the residual carries is attributed to neither', () => { withPosture(undefined); + it('`handBuilt` is the layout a build emits: on compositions that still compose, it equals `jsonLoaded`', () => { + const withResidual = [alpha([pullJob('sync', 'alpha_map'), pullJob('alpha_only', 'alpha_map')]), host([pullJob('host_sync', 'host_map')]), beta]; + expect(handBuilt(withResidual)).toEqual(jsonLoaded(withResidual)); + const bodiesOnly = [alpha([pullJob('sync', 'alpha_map')]), beta]; + expect(handBuilt(bodiesOnly)).toEqual(jsonLoaded(bodiesOnly)); + }); + it('the artifact a build emits carries the pair: the body job copied to the top level, and the residual\'s own job of the same name', () => { - const bundle = jsonLoaded([alpha([pullJob('sync', 'alpha_map')]), host([pullJob('sync', 'host_map')]), beta]); + const bundle = handBuilt([alpha([pullJob('sync', 'alpha_map')]), host([pullJob('sync', 'host_map')]), beta]); expect(bundle.manifest.id).toBe('com.example.beta'); expect(bundle.jobs.map((j: any) => [j.name, j.pull.mapping])).toEqual([['sync', 'alpha_map'], ['sync', 'host_map']]); expect(bundle.packages.map((p: any) => [p.manifest.id, (p.manifest.jobs ?? []).map((j: any) => j.name)])) @@ -858,7 +891,7 @@ describe('[#32355] a job name a package body declares and the residual carries i }); it('JSON-loaded, on a real job service: the name is attributed to neither, and both enabled jobs are refused at bind — never pulled as the body', async () => { - const bundle = jsonLoaded([alpha([pullJob('sync', 'alpha_map')]), host([pullJob('sync', 'host_map')]), beta]); + const bundle = handBuilt([alpha([pullJob('sync', 'alpha_map')]), host([pullJob('sync', 'host_map')]), beta]); const { out, answers, pulls } = await scheduleAndRun(bundle, 'com.example.beta'); // [#32411] Neither is scheduled: one key would have held only the later (the residual's, `host_map`). expect(out.pulls).toEqual([]); @@ -889,7 +922,7 @@ describe('[#32355] a job name a package body declares and the residual carries i it('control: the residual\'s owner IS the one declaring body — one holder, that body; both enabled, refused at bind', async () => { // `alpha` last: the artifact's id is alpha's, so the residual runs as alpha, the body that declares `sync`. - const bundle = jsonLoaded([host([pullJob('sync', 'host_map')]), alpha([pullJob('sync', 'alpha_map')])]); + const bundle = handBuilt([host([pullJob('sync', 'host_map')]), alpha([pullJob('sync', 'alpha_map')])]); expect(bundle.manifest.id).toBe('com.example.alpha'); // Attribution: one holder, alpha, for every job of the name — as before. const of = jobDeclaringPackages(bundle, 'com.example.alpha'); @@ -902,7 +935,7 @@ describe('[#32355] a job name a package body declares and the residual carries i }); it('controls: a residual job with a name of its own binds as today, and a body job with no residual twin binds to its body', async () => { - const bundle = jsonLoaded([ + const bundle = handBuilt([ alpha([pullJob('sync', 'alpha_map'), pullJob('alpha_only', 'alpha_map')]), host([pullJob('host_sync', 'host_map'), pullJob('sync', 'host_map')]), beta, @@ -974,9 +1007,9 @@ describe('[#32411] two enabled jobs of one name in one artifact are refused at b // or alpha's (the residual runs as alpha, the one body declaring `sync`). const ARRANGEMENTS = [ ['the residual runs as a package that does not declare the name', (jobs: { body: unknown[]; residual: unknown[] }) => - ({ bundle: jsonLoaded([alpha(jobs.body), host(jobs.residual), beta]), appId: 'com.example.beta' })], + ({ bundle: handBuilt([alpha(jobs.body), host(jobs.residual), beta]), appId: 'com.example.beta' })], ['the residual runs as the one body that declares the name', (jobs: { body: unknown[]; residual: unknown[] }) => - ({ bundle: jsonLoaded([host(jobs.residual), alpha(jobs.body)]), appId: 'com.example.alpha' })], + ({ bundle: handBuilt([host(jobs.residual), alpha(jobs.body)]), appId: 'com.example.alpha' })], ] as const; /** The `error` calls that carry the coded refusal for `name`: the message, and the error's code and status. */ @@ -1024,7 +1057,7 @@ describe('[#32411] two enabled jobs of one name in one artifact are refused at b const tick = (note: string) => ({ name: 'tick', schedule: INTERVAL, body: { language: 'js', capabilities: [], source: `return; // ${note}` } }); const gamma = defineStack({ manifest: { id: 'com.example.gamma', name: 'Gamma', version: '0.1.0', type: 'module' }, jobs: [tick('gamma')] } as never); const delta = defineStack({ manifest: { id: 'com.example.delta', name: 'Delta', version: '0.1.0', type: 'app' }, jobs: [tick('delta')] } as never); - const bundle = jsonLoaded([gamma, delta]); + const bundle = handBuilt([gamma, delta]); const { out, answers, logger } = await scheduleAndRun(bundle, 'com.example.delta', () => new IntervalJobAdapter()); expect(out.bodies).toEqual([]); expect(out.refused).toEqual(['tick', 'tick']); @@ -1108,7 +1141,7 @@ describe('[#32412] the residual-twin job refusal names the residual as a holder mappings: [{ ...mappingOf('beta_map', 'beta_api'), targetObject: 'beta_record' }], jobs, } as never); - const twin = () => jsonLoaded([alpha([pullJob('sync', 'alpha_map')]), host([pullJob('sync', 'host_map')]), beta]); + const twin = () => handBuilt([alpha([pullJob('sync', 'alpha_map')]), host([pullJob('sync', 'host_map')]), beta]); it('no body carries the artifact\'s id: two candidates — the declaring body and the residual — never one', () => { const bundle = twin(); @@ -1133,7 +1166,7 @@ describe('[#32412] the residual-twin job refusal names the residual as a holder }); it('the residual\'s owner is one of several declaring bodies: every body, then the residual', () => { - const bundle = jsonLoaded([alpha([pullJob('sync', 'alpha_map')]), host([pullJob('sync', 'host_map')]), betaWith([pullJob('sync', 'beta_map')])]); + const bundle = handBuilt([alpha([pullJob('sync', 'alpha_map')]), host([pullJob('sync', 'host_map')]), betaWith([pullJob('sync', 'beta_map')])]); expect(bundle.manifest.id).toBe('com.example.beta'); const of = jobDeclaringPackages(bundle, 'com.example.beta'); for (const job of bundle.jobs) { @@ -1175,9 +1208,9 @@ describe('[#32412] the residual-twin job refusal names the residual as a holder }); it('controls: the one holder (the residual\'s owner IS the one declaring body) and two bodies with no residual twin keep their answers', () => { - const owned = jsonLoaded([host([pullJob('sync', 'host_map')]), alpha([pullJob('sync', 'alpha_map')])]); + const owned = handBuilt([host([pullJob('sync', 'host_map')]), alpha([pullJob('sync', 'alpha_map')])]); for (const job of owned.jobs) expect(jobDeclaringPackages(owned, 'com.example.alpha')(job)).toBe('com.example.alpha'); - const twoBodies = jsonLoaded([alpha([pullJob('sync', 'alpha_map')]), betaWith([pullJob('sync', 'beta_map')])]); + const twoBodies = handBuilt([alpha([pullJob('sync', 'alpha_map')]), betaWith([pullJob('sync', 'beta_map')])]); // No residual job: met by name, the #32071 refusal names the two bodies and nothing else. expect((jobDeclaringPackages(twoBodies, 'com.example.beta')(pullJob('sync', 'alpha_map')) as { candidates?: unknown }).candidates) .toEqual([ALPHA, { kind: 'package', packageId: 'com.example.beta' }]); @@ -1200,9 +1233,9 @@ describe('[#32572] collectJobNameCollisions answers the refusals the binder refu const ARRANGEMENTS = [ ['a package body and the residual (the residual runs as no declaring body)', - () => ({ bundle: jsonLoaded([alpha([pullJob('sync', 'alpha_map')]), host([pullJob('sync', 'host_map')]), beta]), appId: 'com.example.beta' })], + () => ({ bundle: handBuilt([alpha([pullJob('sync', 'alpha_map')]), host([pullJob('sync', 'host_map')]), beta]), appId: 'com.example.beta' })], ['a package body and the residual (the residual runs as that body)', - () => ({ bundle: jsonLoaded([host([pullJob('sync', 'host_map')]), alpha([pullJob('sync', 'alpha_map')])]), appId: 'com.example.alpha' })], + () => ({ bundle: handBuilt([host([pullJob('sync', 'host_map')]), alpha([pullJob('sync', 'alpha_map')])]), appId: 'com.example.alpha' })], ['a single-package artifact listing two names twice', () => ({ bundle: { id: APP_ID, version: '0.1.0', type: 'app', mappings: [MAPPING], jobs: [ { ...PULL_JOB, name: 'twice' }, { ...PULL_JOB, name: 'again' }, { ...PULL_JOB, name: 'twice' }, { ...PULL_JOB, name: 'again' }, diff --git a/packages/runtime/src/app-artifact-handlers.ts b/packages/runtime/src/app-artifact-handlers.ts index 2fd78e09ce3..9ef27072ac9 100644 --- a/packages/runtime/src/app-artifact-handlers.ts +++ b/packages/runtime/src/app-artifact-handlers.ts @@ -1288,7 +1288,8 @@ export function judgeJobPull( * that name than its bodies declare — the flattened top level copies each * body job once, so every job of the name beyond those copies is a top-level * job of its own (`composeStacks(…, { manifest: 'preserve' })` with an input - * that has no `manifest`). By count, never by comparing a copy's content with + * that has no `manifest`, which composes such a pair only when one of the two + * is disabled; an enabled pair it refuses). By count, never by comparing a copy's content with * its body's: a conversion replays a body under its own version window, so a * genuine copy need not stay equal to the body it was copied from. Such a name * answers the one holder when the body and the residual's owner are one @@ -1390,12 +1391,18 @@ function describeJobRunForm(job: unknown): string { * with nothing said. Nothing picks one of them, so the name is refused: none of its jobs is scheduled. * * The holders the refusal names are every body declaring the name, and — when the artifact holds more jobs - * of the name than its bodies declare (the residual's own, `composeStacks(…, { manifest: 'preserve' })` with - * an input that has no `manifest`) — the artifact's top level outside every package body, as - * {@link jobNameRefusal} names it; an artifact without `packages[]` is its app's alone. The refusal's - * `candidates` are every declaring body as a `package`, then the residual as `{ kind: 'residual', ownerId }` - * (the artifact's id), or the app itself for an artifact without `packages[]`. Each job is named by - * its run form. Counted by name, never by content: a conversion replays a body under its own version window. + * of the name than its bodies declare (the residual's own: a top-level job of an input with no `manifest`) — + * the artifact's top level outside every package body, as {@link jobNameRefusal} names it; an artifact + * without `packages[]` is its app's alone. The refusal's `candidates` are every declaring body as a + * `package`, then the residual as `{ kind: 'residual', ownerId }` (the artifact's id), or the app itself for + * an artifact without `packages[]`. Each job is named by its run form. Counted by name, never by content: a + * conversion replays a body under its own version window. + * + * `composeStacks` refuses the same names by the same reading (enabled jobs only, by name, each job counted + * per place it is reached — one job object two bodies carry is two jobs here — and the residual by count + * beyond the bodies' copies), so a composition does not build an artifact this refuses. This stays the + * backstop for an artifact no composition built: hand-written, or built before composition judged a shared + * job name. * * A disabled job is scheduled by nothing, so it collides with nothing and is not counted: its enabled twin * keeps the run-time attribution refusal {@link jobDeclaringPackages} gives it. diff --git a/packages/spec/src/migrations/entries/semantic/18.compose-stacks-job-name-across-packages-refused.ts b/packages/spec/src/migrations/entries/semantic/18.compose-stacks-job-name-across-packages-refused.ts new file mode 100644 index 00000000000..9ba3bd2fbea --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.compose-stacks-job-name-across-packages-refused.ts @@ -0,0 +1,40 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// An accept-set narrowing of composition. The boot's job binder schedules every +// job of an artifact by its bare name, whichever package declares it, and +// refuses a name two enabled jobs share: none of them is scheduled. The +// install-local door refuses such a package by the same judge. Composition now +// refuses it too, reading the artifact the way the binder does (enabled jobs +// only, by name, the residual by count beyond the package bodies' flattened +// copies), so the composition, the install door and the binder agree. No D2 +// conversion: which of two jobs to keep, or to rename, is the author's call. +export const entry: SemanticMigration = { + id: 'compose-stacks-job-name-across-packages-refused', + surface: + 'composeStacks(…) whose result carries packages[]: one job name enabled in two package bodies, or in a package ' + + "body and the residual (a top-level job no body declares: under manifest 'preserve' an input with no manifest, " + + "under 'first', 'last' or an index any top-level job beside an input that is itself a multi-package artifact). " + + 'Before this release the pair composed: two bodies were never read against each other, and a residual job ' + + "sharing a body job's name was read as that body's copy. Also refused now: two residual jobs of one name beside " + + 'a package body job of that name (the one-package finding, a disabled job counted too; before, both were read ' + + "as that body's copies), and one job object a composition reaches twice (a built stack shared by two " + + 'compositions, or passed twice), counted per place as the binder binds each copy.', + replacement: + 'Give each job its own name across the composed artifact, or disable all but one of the jobs that share a name ' + + '(enabled: false). A disabled job is scheduled by nothing, so a disabled twin still composes.', + reason: + 'The job binder keys every job of an artifact by its bare name and refuses a name two enabled jobs share, so the ' + + 'boot scheduled none of them (NOT SCHEDULED at error) and every scheduled run of that name was silently lost; ' + + 'the install-local door already refused such a package. Composition now refuses the pair ' + + '(STACK_CROSS_REFERENCE_INVALID) naming every enabled job of the name and where it sits, a residual job marked ' + + 'as the top level outside every package body. A body job\'s own flattened copy is not a second job: the ' + + 'residual is counted beyond the copies, never by content. An artifact built before this keeps loading, and the ' + + 'binder still refuses the name at boot.', + acceptanceCriteria: + 'objectstack validate and objectstack build load the composed stack without a STACK_CROSS_REFERENCE_INVALID ' + + 'finding "Job \'NAME\' is declared enabled twice across the packages of one composed artifact" or "Job \'NAME\' ' + + 'is declared twice in jobs", and the boot log carries no NOT SCHEDULED error for a job name: composition counts ' + + 'each job once per place it is reached, as the binder binds it.', +}; diff --git a/packages/spec/src/stack-compose-duplicate-entry-census.test.ts b/packages/spec/src/stack-compose-duplicate-entry-census.test.ts index 5dab018f049..05a9282098c 100644 --- a/packages/spec/src/stack-compose-duplicate-entry-census.test.ts +++ b/packages/spec/src/stack-compose-duplicate-entry-census.test.ts @@ -237,7 +237,9 @@ describe('composeStacks - CONTROL: two packages each declaring one entry under o row.key === 'apis' ? { artifactFlows: ['dupe_flow'] } : undefined, ); - it.each(CENSUS.filter((row) => row.key !== 'objects').map((row) => [row.key, row] as const))( + // `jobs` is not here: one job name enabled in two packages is refused across them + // (`stack-composed-job-name-across-holders.test.ts`), since the boot schedules a job by its bare name. + it.each(CENSUS.filter((row) => row.key !== 'objects' && row.key !== 'jobs').map((row) => [row.key, row] as const))( '%s: under `manifest: \'preserve\'` each body is judged on its own, and the pair composes', (_key, row) => { const r = refusalOf(() => composeStacks([firstInput(row), otherPackage(row)], { manifest: 'preserve' })); diff --git a/packages/spec/src/stack-composed-job-name-across-holders.test.ts b/packages/spec/src/stack-composed-job-name-across-holders.test.ts new file mode 100644 index 00000000000..5f63f34ab27 --- /dev/null +++ b/packages/spec/src/stack-composed-job-name-across-holders.test.ts @@ -0,0 +1,293 @@ +/** + * One job name ENABLED in two holders of a composed artifact — two package + * bodies, or a package body and the residual (the top-level entries no body + * claims) — is refused at composition. + * + * The boot's job binder (`jobNameCollisions`, `@objectstack/runtime`) schedules + * every job of an artifact by its bare name and refuses a name two enabled jobs + * share, so neither runs; the install-local door refuses such a package by the + * same judge. Composition used to admit both shapes: a residual job was claimed + * as a body's copy by NAME, and two bodies were never read against each other. + * It now reads the artifact the way the binder does — enabled jobs only, by + * name, the residual by count beyond the bodies' copies — so a disabled twin, + * a body's own flattened copy and distinct names still compose. + */ +import { describe, it, expect } from 'vitest'; +import { composeStacks, defineStack } from './stack.zod'; + +const sales = { id: 'com.example.sales', namespace: 'crm', name: 'sales', version: '1.0.0', type: 'app' as const }; +const billing = { id: 'com.example.billing', namespace: 'crm', name: 'billing', version: '1.0.0', type: 'module' as const }; +const support = { id: 'com.example.support', namespace: 'crm', name: 'support', version: '1.0.0', type: 'module' as const }; + +const line = { name: 'crm_line', label: 'Line', sharingModel: 'private' as const, fields: { title: { type: 'text' as const, label: 'Title' } } }; +const job = (label: string, name = 'crm_nightly', enabled?: boolean) => ({ + name, + label, + schedule: { type: 'interval' as const, intervalMs: 60000 }, + body: { language: 'js' as const, source: 'return 1;', capabilities: [] }, + ...(enabled === undefined ? {} : { enabled }), +}); + +interface Refusal { code?: string; status?: number; issues?: readonly string[]; message: string } + +function refusalOf(run: () => unknown): Refusal | null { + try { + run(); + return null; + } catch (e) { + return e as Refusal; + } +} + +function expectOneIssue(r: Refusal | null): asserts r is Refusal { + expect(r, 'refused').not.toBeNull(); + expect(r!.code).toBe('STACK_CROSS_REFERENCE_INVALID'); + expect(r!.status).toBe(422); + expect(r!.issues).toHaveLength(1); +} + +const CONSEQUENCE = + "The runtime schedules an artifact's jobs by their bare name, whichever package declares them, and the job " + + 'scheduler refuses a name two enabled jobs share, so none of them runs.'; +const REMEDY_TWO = 'Rename one of them, or disable one (`enabled: false`).'; +const RESIDUAL = '(the top level, outside every package body)'; + +describe('two package bodies with one enabled job name', () => { + it('refused at composition, naming both bodies', () => { + const r = refusalOf(() => + composeStacks( + [defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] }), defineStack({ manifest: billing, jobs: [job('Billing')] })], + { manifest: 'preserve' }, + ), + ); + expectOneIssue(r); + expect(r.issues![0]).toBe( + "Job 'crm_nightly' is declared enabled twice across the packages of one composed artifact: " + + "'com.example.sales' (stack #0) jobs[0] and 'com.example.billing' (stack #1) jobs[0]. " + + `${CONSEQUENCE} ${REMEDY_TWO}`, + ); + }); + + it('two bodies a nested artifact carries: refused, each named at its packages[] place', () => { + const r = refusalOf(() => + composeStacks( + [ + composeStacks( + [defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] }), defineStack({ manifest: support })], + { manifest: 'preserve' }, + ), + defineStack({ manifest: billing, jobs: [job('Billing')] }), + ], + { manifest: 'preserve' }, + ), + ); + expectOneIssue(r); + expect(r.issues![0]).toBe( + "Job 'crm_nightly' is declared enabled twice across the packages of one composed artifact: " + + "'com.example.support' (stack #0) packages[0].manifest.jobs[0] and 'com.example.billing' (stack #1) jobs[0]. " + + `${CONSEQUENCE} ${REMEDY_TWO}`, + ); + }); + + it('three holders: every enabled job named, and the remedy is all but one', () => { + const r = refusalOf(() => + composeStacks( + [ + defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] }), + defineStack({ manifest: billing, jobs: [job('Billing')] }), + defineStack({ manifest: support, jobs: [job('Support')] }), + ], + { manifest: 'preserve' }, + ), + ); + expectOneIssue(r); + expect(r.issues![0]).toMatch(/^Job 'crm_nightly' is declared enabled 3 times across the packages of one composed artifact: /); + expect(r.issues![0]).toContain("'com.example.sales' (stack #0) jobs[0], 'com.example.billing' (stack #1) jobs[0] and 'com.example.support' (stack #2) jobs[0]"); + expect(r.issues![0]).toContain('Rename all but one of them, or disable all but one (`enabled: false`).'); + }); +}); + +describe('a residual job sharing an enabled name with a package body\'s job', () => { + it('refused at composition, naming the body and the residual', () => { + const r = refusalOf(() => + composeStacks( + [ + defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] }), + defineStack({ jobs: [job('Residual')] }), + defineStack({ manifest: billing }), + ], + { manifest: 'preserve' }, + ), + ); + expectOneIssue(r); + expect(r.issues![0]).toBe( + "Job 'crm_nightly' is declared enabled twice across the packages of one composed artifact: " + + `'com.example.sales' (stack #0) jobs[0] and stack #1 jobs[0] ${RESIDUAL}. ${CONSEQUENCE} ${REMEDY_TWO}`, + ); + }); + + it('the residual before the body, and its owner the declaring body: the residual still named as the residual', () => { + const r = refusalOf(() => + composeStacks( + [defineStack({ jobs: [job('Residual')] }), defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] })], + { manifest: 'preserve' }, + ), + ); + expectOneIssue(r); + expect(r.issues![0]).toContain(`stack #0 jobs[0] ${RESIDUAL} and 'com.example.sales' (stack #1) jobs[0]`); + }); + + it.each(['first', 'last'] as const)( + '`%s`: a residual job beside a nested artifact whose body declares the name is refused, by count beyond the copies', + (strategy) => { + // The nested artifact keeps its flattened top level (it has a residual of its own), so its body's job + // is there twice: in the body and as the copy. Only the outer residual's job is beyond the copies. + const nested = composeStacks( + [defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] }), defineStack({ jobs: [job('Own', 'crm_own')] }), defineStack({ manifest: support })], + { manifest: 'preserve' }, + ); + expect((nested as { jobs?: unknown[] }).jobs, 'anti-vacuity: the nested artifact carries the copy').toHaveLength(2); + const r = refusalOf(() => composeStacks([nested, defineStack({ jobs: [job('Residual')] })], { manifest: strategy })); + expectOneIssue(r); + expect(r.issues![0]).toBe( + "Job 'crm_nightly' is declared enabled twice across the packages of one composed artifact: " + + `'com.example.support' (stack #0) packages[0].manifest.jobs[0] and stack #1 jobs[0] ${RESIDUAL}. ${CONSEQUENCE} ${REMEDY_TWO}`, + ); + }, + ); + + it('a residual job beside a nested artifact that dropped its flattened copy: refused all the same', () => { + const nested = composeStacks( + [defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] }), defineStack({ manifest: support })], + { manifest: 'preserve' }, + ); + expect((nested as { jobs?: unknown[] }).jobs, 'anti-vacuity: no flattened copy').toBeUndefined(); + const r = refusalOf(() => composeStacks([nested, defineStack({ jobs: [job('Residual')] })], { manifest: 'last' })); + expectOneIssue(r); + expect(r.issues![0]).toContain(`'com.example.support' (stack #0) packages[0].manifest.jobs[0] and stack #1 jobs[0] ${RESIDUAL}`); + }); +}); + +describe('one job OBJECT reached through two places is two jobs of the name, as the binder binds both', () => { + // A flat composition concatenates by reference, so a built stack shared by two compositions puts the + // same job object in both. The binder binds each copy an artifact carries, so it is counted per place. + const base = () => defineStack({ jobs: [job('Shared')] }); + + it('one job object in two package bodies: refused, naming both bodies', () => { + const shared = base(); + const a = composeStacks([shared, defineStack({ manifest: sales, objects: [line] })]); + const b = composeStacks([shared, defineStack({ manifest: billing })]); + const r = refusalOf(() => composeStacks([a, b], { manifest: 'preserve' })); + expectOneIssue(r); + expect(r.issues![0]).toBe( + "Job 'crm_nightly' is declared enabled twice across the packages of one composed artifact: " + + `'com.example.sales' (stack #0) jobs[0] and 'com.example.billing' (stack #1) jobs[0]. ${CONSEQUENCE} ${REMEDY_TWO}`, + ); + }); + + it('one job object in a package body and the residual: refused, naming the body and the residual', () => { + const shared = base(); + const a = composeStacks([shared, defineStack({ manifest: sales, objects: [line] })]); + const r = refusalOf(() => composeStacks([a, shared], { manifest: 'preserve' })); + expectOneIssue(r); + expect(r.issues![0]).toBe( + "Job 'crm_nightly' is declared enabled twice across the packages of one composed artifact: " + + `'com.example.sales' (stack #0) jobs[0] and stack #1 jobs[0] ${RESIDUAL}. ${CONSEQUENCE} ${REMEDY_TWO}`, + ); + }); + + it('one job object twice in one holder (the same built stack passed twice): refused as that package\'s pair', () => { + const shared = base(); + const r = refusalOf(() => composeStacks([defineStack({ manifest: sales, objects: [line] }), shared, shared])); + expectOneIssue(r); + expect(r.issues![0]).toMatch(/^Job 'crm_nightly' is declared twice in `jobs`: stack #1 jobs\[0\] and stack #2 jobs\[0\]\. /); + }); +}); + +describe('CONTROLS: what the binder schedules without a refusal still composes', () => { + it('a body\'s job alone: its flattened copy is not read as a residual twin', () => { + const composed = composeStacks( + [ + defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] }), + defineStack({ jobs: [job('Residual', 'crm_hourly')] }), + defineStack({ manifest: billing }), + ], + { manifest: 'preserve' }, + ) as unknown as { jobs: Array<{ name: string }> }; + expect(composed.jobs.map((j) => j.name), 'anti-vacuity: the copy and the residual sit at the top level').toEqual(['crm_nightly', 'crm_hourly']); + }); + + it('a nested artifact\'s flattened copy, composed again: not read as a second job of the name', () => { + const nested = composeStacks( + [defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] }), defineStack({ jobs: [job('Own', 'crm_own')] }), defineStack({ manifest: support })], + { manifest: 'preserve' }, + ); + expect(refusalOf(() => composeStacks([nested, defineStack({ manifest: billing })], { manifest: 'preserve' }))).toBeNull(); + expect(refusalOf(() => composeStacks([nested, defineStack({ jobs: [job('Hourly', 'crm_hourly')] })], { manifest: 'last' }))).toBeNull(); + }); + + it('a nested artifact read back through JSON: its copies are other objects now, and still counted as copies, not by content', () => { + const nested = composeStacks( + [defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] }), defineStack({ jobs: [job('Own', 'crm_own')] }), defineStack({ manifest: support })], + { manifest: 'preserve' }, + ); + const reloaded = defineStack(JSON.parse(JSON.stringify(nested))); + const carried = reloaded as unknown as { jobs: unknown[]; packages: Array<{ manifest: { jobs: unknown[] } }> }; + expect(carried.jobs[0], 'anti-vacuity: the copy is not the body\'s job object').not.toBe(carried.packages[0].manifest.jobs[0]); + expect(refusalOf(() => composeStacks([reloaded, defineStack({ manifest: billing })], { manifest: 'preserve' }))).toBeNull(); + // …and a job beyond the copies is still the residual's. + const r = refusalOf(() => composeStacks([reloaded, defineStack({ manifest: billing, jobs: [job('Billing', 'crm_own')] })], { manifest: 'preserve' })); + expectOneIssue(r); + expect(r.issues![0]).toContain(`'com.example.support' (stack #0) jobs[1] ${RESIDUAL} and 'com.example.billing' (stack #1) jobs[0]`); + }); + + it.each([ + ['the first body\'s twin', [false, undefined]], + ['the second body\'s twin', [undefined, false]], + ] as const)('a disabled twin across two bodies composes: %s', (_label, [first, second]) => { + expect(refusalOf(() => + composeStacks( + [ + defineStack({ manifest: sales, objects: [line], jobs: [job('Sales', 'crm_nightly', first)] }), + defineStack({ manifest: billing, jobs: [job('Billing', 'crm_nightly', second)] }), + ], + { manifest: 'preserve' }, + ), + )).toBeNull(); + }); + + it.each([ + ['the body\'s twin', [false, undefined]], + ['the residual\'s twin', [undefined, false]], + ] as const)('a disabled twin across a body and the residual composes: %s', (_label, [body, residual]) => { + expect(refusalOf(() => + composeStacks( + [ + defineStack({ manifest: sales, objects: [line], jobs: [job('Sales', 'crm_nightly', body)] }), + defineStack({ jobs: [job('Residual', 'crm_nightly', residual)] }), + defineStack({ manifest: billing }), + ], + { manifest: 'preserve' }, + ), + )).toBeNull(); + }); + + it('distinct names across two bodies and the residual compose', () => { + expect(refusalOf(() => + composeStacks( + [ + defineStack({ manifest: sales, objects: [line], jobs: [job('Sales', 'crm_sales')] }), + defineStack({ jobs: [job('Residual', 'crm_residual')] }), + defineStack({ manifest: billing, jobs: [job('Billing', 'crm_billing')] }), + ], + { manifest: 'preserve' }, + ), + )).toBeNull(); + }); + + it('a flat composition is one package: its pair is the one-package finding, not this one', () => { + const r = refusalOf(() => composeStacks([defineStack({ jobs: [job('First')] }), defineStack({ jobs: [job('Second')] })])); + expectOneIssue(r); + expect(r.issues![0]).toMatch(/^Job 'crm_nightly' is declared twice in `jobs`: stack #0 jobs\[0\] and stack #1 jobs\[0\]\. /); + }); +}); diff --git a/packages/spec/src/stack-residual-extension-jobs.test.ts b/packages/spec/src/stack-residual-extension-jobs.test.ts index 9fd0e753c37..b60971c47b7 100644 --- a/packages/spec/src/stack-residual-extension-jobs.test.ts +++ b/packages/spec/src/stack-residual-extension-jobs.test.ts @@ -96,10 +96,15 @@ describe('residual jobs under `preserve` are judged as one package', () => { expect(composed.jobs.map((j) => j.name)).toEqual(['crm_nightly']); }); + // Each body's job under a name of its own: one name enabled in two bodies is refused across the + // packages (`stack-composed-job-name-across-holders.test.ts`), not as a residual pair. it('CONTROL: a job each body declares stays each body\'s, not a residual pair', () => { expect(refusalOf(() => composeStacks( - [defineStack({ manifest: sales, objects: [line], jobs: [job('Sales')] }), defineStack({ manifest: billing, jobs: [job('Billing')] })], + [ + defineStack({ manifest: sales, objects: [line], jobs: [{ ...job('Sales'), name: 'crm_sales_nightly' }] }), + defineStack({ manifest: billing, jobs: [{ ...job('Billing'), name: 'crm_billing_nightly' }] }), + ], { manifest: 'preserve' }, ), )).toBeNull(); diff --git a/packages/spec/src/stack.zod.ts b/packages/spec/src/stack.zod.ts index 717d193aae1..c2745d28bf7 100644 --- a/packages/spec/src/stack.zod.ts +++ b/packages/spec/src/stack.zod.ts @@ -388,10 +388,10 @@ function applyCollectionItemOwnerStampGate( * that no body declares is registered under `manifest.id` and its stamp is * judged at both doors, like every other residual item. * A package BODY's items of these collections are still judged, at both doors. - * This is the owner-stamp mirror only: the composition's duplicate-entry door - * still judges two top-level `jobs` no body declares as one package's - * ({@link residualEntryPredicate}), since the boot's job binder schedules - * neither of two enabled jobs of one name. + * This is the owner-stamp mirror only: the composition still judges the + * residual's `jobs` — two of one name as one package's pair, and one sharing + * an enabled name with a body's job — ({@link composedJobDeclarations}), since + * the boot's job binder schedules neither of two enabled jobs of one name. * * Mirrored, because `@objectstack/spec` cannot import the rule it mirrors; a * `@objectstack/metadata` test holds the two equal, collection by collection. @@ -3339,7 +3339,10 @@ function collectDuplicateFunctionNameErrors(config: ObjectStackDefinition): stri * collide here too. Cross-package reuse of a name is untouched (ADR-0048 §3.4): * a multi-package project (`composeStacks(…, { manifest: 'preserve' })`) * carries each package's collections in its own `packages[i]` body, and each - * body is judged on its own, never against another. The same-package case is + * body is judged on its own, never against another (an enabled job name is the + * one exception, judged across a composition's packages by + * {@link collectComposedJobNameErrors}: the boot schedules a job by its bare + * name, whichever package declares it). The same-package case is * the one §3.4 leaves to authoring-time hygiene (`os lint`'s duplicate-name * advisory); it is refused here at the contract, as the action-key check * already does for actions. @@ -3505,7 +3508,8 @@ interface PackageCollectionEntry { * ONE package: `entriesOf(key)` lists that package's entries of `key`, each * labelled with where it sits, or `undefined` when the package carries none. * Every door below hands it one package and nothing else, so cross-package - * reuse of a name is never read here (ADR-0048 §3.4). The finding's wording is + * reuse of a name is never read here (ADR-0048 §3.4); a job name enabled in two + * packages of a composition is {@link collectComposedJobNameErrors}'s. The finding's wording is * the same at every door; only the origins differ. */ function duplicateEntryFindings( @@ -3564,7 +3568,8 @@ function collectDuplicateEntryErrors(config: ObjectStackDefinition): string[] { * `registerApp` exactly as a single-package stack's top level is, so two * entries under one identity in one body lose one entry at the boot just the * same. Each body is judged alone: two bodies reusing a name is the - * cross-package reuse ADR-0048 §3.4 allows, and two bodies under ONE package id + * cross-package reuse ADR-0048 §3.4 allows (except an enabled job name, which + * the boot schedules by its bare name: {@link collectComposedJobNameErrors}), and two bodies under ONE package id * are the boot's own `DUPLICATE_ARTIFACT_PACKAGE` refusal, not this one. * `label(i)` spells where body `i` sits for the finding's origins. */ @@ -3604,7 +3609,10 @@ function collectPackageBodyDuplicateEntryErrors( * own collections of an input that carries `packages[]` — is one package, * and two of its entries under one identity are refused with the one-stack * wording. That includes two of its `jobs` of one name: the boot reads jobs - * off the stack whole and its binder schedules neither. + * off the stack whole and its binder schedules neither. The residual's jobs + * are read by count beyond the bodies' copies + * ({@link composedJobDeclarations}); one sharing an enabled name with a + * body's job is {@link collectComposedJobNameErrors}'s. * * The residual registers under `manifest.id`, and under `'preserve'` that id * is also a body's: the last input with a manifest. The registry keeps one @@ -3628,8 +3636,11 @@ function collectPackageBodyDuplicateEntryErrors( * (`collectBundleHooks` collects by identity), but a built artifact carries two * equal hook entries, and the table's `hooks` line records that every entry's * handler is bound and runs — so a hook reached twice is counted twice and - * refused. Two distinct entries count however alike they are, as in a single - * stack. + * refused. `jobs` are counted the same way, per place reached + * ({@link composedJobDeclarations}): the job binder schedules every copy an + * artifact carries by its name, so a job reached twice is two enabled jobs of + * the name and neither runs. Two distinct entries count however alike they + * are, as in a single stack. */ function collectComposedResidualDuplicateEntryErrors( stacks: readonly ObjectStackDefinition[], @@ -3640,6 +3651,12 @@ function collectComposedResidualDuplicateEntryErrors( const isResidual = residualEntryPredicate(composedPackages); return duplicateEntryFindings( (key) => { + // The residual's jobs are read where every holder's jobs are read, by + // count beyond the bodies' copies ({@link composedJobDeclarations}). + if (key === 'jobs') { + const residual = composedJobDeclarations(stacks, preserve).filter((d) => d.holder === RESIDUAL_JOB_HOLDER); + return residual.length > 0 ? residual : undefined; + } const entries: PackageCollectionEntry[] = []; const seen = new Set(); let declared = false; @@ -3727,24 +3744,16 @@ function composedPackageBodies(composedPackages: unknown): Record boolean { const bodies = composedPackageBodies(composedPackages); @@ -3780,6 +3789,141 @@ function residualEntryPredicate(composedPackages: unknown): (key: string, entry: }; } +/** The holder {@link composedJobDeclarations} files a residual job under. */ +const RESIDUAL_JOB_HOLDER = 'residual'; + +/** One job a composed artifact declares, where it sits, and which holder declares it. */ +interface ComposedJobDeclaration extends PackageCollectionEntry { + /** A package body (`body:INPUT` or `body:INPUT:INDEX`) or {@link RESIDUAL_JOB_HOLDER}. */ + readonly holder: string; +} + +/** + * Every job a composed artifact declares, each once, with its holder: the + * reading the boot's job binder makes of the artifact (`jobNameCollisions`, + * `@objectstack/runtime`), taken input by input. + * + * - An input that carries `packages[]` (a nested artifact): each carried body's + * jobs are that body's (`INPUT packages[P].manifest.jobs[J]`). Its own + * top-level jobs are the flattened copies of those bodies' jobs plus its own + * residual: a top-level job beyond the copies is the residual's. By COUNT, + * as the binder counts (the artifact holds more jobs of the name than its + * bodies declare), never by content, since a conversion replays a body under + * its own version window and a genuine copy need not stay equal to it. A + * top-level job that IS a body's job object is matched to it first, so the + * residual's own job is the one named, whatever the order. + * - Under `manifest: 'preserve'`, an input with a manifest is assembled into a + * body, so its jobs are that body's (`INPUT jobs[J]`). + * - Any other input's jobs reach the artifact's top level and no body: the + * residual's. With no body anywhere (a flat composition) that is every job. + * + * A job is counted once per place it is reached, the same job OBJECT reached + * through two inputs included (a built stack shared by two compositions, or + * passed twice): the boot binds every copy an artifact carries — the binder + * reads the bodies' jobs with no dedupe between them, and the top level's + * twice when it lists one twice — so two places are two jobs of the name, as + * `hooks` are counted at {@link collectComposedResidualDuplicateEntryErrors}. + * Only a nested input's flattened copies of its own bodies' jobs are not + * counted again, matched as above. + */ +function composedJobDeclarations( + stacks: readonly ObjectStackDefinition[], + preserve: boolean, +): ComposedJobDeclaration[] { + const declarations: ComposedJobDeclaration[] = []; + const declare = (entry: unknown, origin: string, holder: string): void => { + declarations.push({ entry, origin, holder }); + }; + for (const [i, stack] of stacks.entries()) { + const label = stackLabel(stack, i); + const own: unknown = (stack as Record).jobs; + const carried: unknown = (stack as Record).packages; + if (Array.isArray(carried)) { + const copies = new Map(); + const bodyJobs = new Set(); + for (const [p, entry] of carried.entries()) { + const body: unknown = isRecord(entry) ? entry.manifest : undefined; + if (!isRecord(body) || !Array.isArray(body.jobs)) continue; + for (const [j, job] of body.jobs.entries()) { + declare(job, `${label} packages[${p}].manifest.jobs[${j}]`, `body:${i}:${p}`); + bodyJobs.add(job); + const name = readEntryName(job); + if (name !== undefined) copies.set(name, (copies.get(name) ?? 0) + 1); + } + } + if (!Array.isArray(own)) continue; + const consume = (name: string | undefined): boolean => { + const left = name === undefined ? 0 : copies.get(name) ?? 0; + if (left === 0) return false; + copies.set(name as string, left - 1); + return true; + }; + const unmatched = own.flatMap((job, j) => (bodyJobs.has(job) && consume(readEntryName(job)) ? [] : [j])); + for (const j of unmatched) { + if (!consume(readEntryName(own[j]))) declare(own[j], `${label} jobs[${j}]`, RESIDUAL_JOB_HOLDER); + } + continue; + } + if (!Array.isArray(own)) continue; + const holder = preserve && stack.manifest ? `body:${i}` : RESIDUAL_JOB_HOLDER; + own.forEach((job, j) => declare(job, `${label} jobs[${j}]`, holder)); + } + return declarations; +} + +/** + * [#36431] One job name ENABLED in more than one holder of a composed + * artifact — two package bodies, or a body and the residual — one refusal line + * per name, naming every enabled job of it. + * + * The boot's job binder schedules every job of an artifact under the + * artifact's id, keyed by its bare name whichever package declares it, and + * refuses a name two enabled jobs share: neither is scheduled + * (`jobNameCollisions`, `@objectstack/runtime`, ADR-0150 D3). The install-local + * door refuses such a package by the same judge (`collectJobNameCollisions`), + * so the door and the binder cannot disagree about a shared name; this is that + * judge at composition, over {@link composedJobDeclarations}, so a composition + * never builds an artifact whose boot silently schedules none of the name. + * Its reading is the binder's: enabled jobs only (a disabled job is scheduled + * by nothing, so a disabled twin composes), counted by name and per place + * reached, the residual by count beyond the bodies' copies. Cross-package reuse of a name (ADR-0048 + * §3.4) does not reach jobs: nothing resolves a bare job name to a package. + * + * Only names that span two holders: two jobs of one name in one holder are + * that package's pair, refused by its own door + * ({@link collectComposedPackageBodyDuplicateEntryErrors}, + * {@link collectComposedResidualDuplicateEntryErrors}). An artifact no + * composition built (hand-written, or built before this) still meets the + * binder's refusal at boot. + */ +function collectComposedJobNameErrors( + stacks: readonly ObjectStackDefinition[], + preserve: boolean, +): string[] { + const enabledByName = new Map(); + for (const declaration of composedJobDeclarations(stacks, preserve)) { + const name = readEntryName(declaration.entry); + if (name === undefined || (declaration.entry as { enabled?: unknown }).enabled === false) continue; + enabledByName.set(name, [...(enabledByName.get(name) ?? []), declaration]); + } + const errors: string[] = []; + for (const [name, declared] of enabledByName) { + if (new Set(declared.map((d) => d.holder)).size < 2) continue; + const origins = declared.map((d) => + d.holder === RESIDUAL_JOB_HOLDER ? `${d.origin} (the top level, outside every package body)` : d.origin, + ); + const many = declared.length > 2; + errors.push( + `Job '${name}' is declared enabled ${many ? `${declared.length} times` : 'twice'} across the packages of one composed artifact: ` + + `${joinDeclarationOrigins(origins)}. The runtime schedules an artifact's jobs by their bare name, ` + + 'whichever package declares them, and the job scheduler refuses a name two enabled jobs share, so none ' + + `of them runs. Rename ${many ? 'all but one' : 'one'} of them, or disable ${many ? 'all but one' : 'one'} ` + + '(`enabled: false`).', + ); + } + return errors; +} + /** * The composition door for package BODIES: every `packages[i]` body the * composed artifact carries, in the order it carries them (a nested artifact's @@ -9850,6 +9994,9 @@ function composeBuiltStacks( // manifest strategy, and every package body the artifact carries, each on // its own — see {@link collectComposedResidualDuplicateEntryErrors} and // {@link collectComposedPackageBodyDuplicateEntryErrors}. + // [#36431] …and one job name enabled in two holders of the result (two + // package bodies, or a body and the residual): the boot's job binder + // schedules none of the name — see {@link collectComposedJobNameErrors}. const artifactCrossRefErrors = [ ...collectArtifactCrossReferenceErrors( stacks, @@ -9862,6 +10009,7 @@ function composeBuiltStacks( ...collectArtifactFlowClaimErrors(stacks), ...collectComposedResidualDuplicateEntryErrors(stacks, composed.packages, (composed.manifest as { id?: unknown } | undefined)?.id, opts.manifest === 'preserve'), ...collectComposedPackageBodyDuplicateEntryErrors(stacks, opts.manifest === 'preserve'), + ...collectComposedJobNameErrors(stacks, opts.manifest === 'preserve'), ]; if (artifactCrossRefErrors.length > 0) { const count = artifactCrossRefErrors.length;