Skip to content

Commit ade13d3

Browse files
fix(cloud-connection, runtime)!: install-local refuses a package with two enabled jobs of one name, as the binder refuses the name at bind (#32889)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuNCRstR4ui2WukRu5DzDKPR)_ Fixes #32572 domain:server#7 · os-sales · session_01L6bhgTHn5TtkSoqxQzSJ34 (card thread; claim 6836648648) Clause-②: yes (narrowing) — the narrowing: `POST /api/v1/marketplace/install-local` refuses a package with two or more enabled jobs of one name with `422 VALIDATION_ERROR`, where it answered `200` and none of those jobs ran: with package-authored scheduled work on, the binder then refused the name at bind and cancelled the job of that name the installed version ran; with it off (`OS_AUTOMATION_SCHEDULED_WORK_ENABLED` unset, the default) or with no job service, the package installed whole with every job withheld, and an upgrade to it landed. The door judges the package whatever the switch, as it already judges a job with no `body`. The widening: `@objectstack/runtime` exports `collectJobNameCollisions(bundle, appId)`, the binder's own shared-name judgement (`jobNameCollisions`) the door refuses by — a name added to the package's entry, so the public surface grows (the claim expected `no (narrowing)`; measured `yes` because of that export, the one way to share the bind's judgement without a second copy in the door). Metadata-protocol: none — no key, value or metadata type an author writes changes; what moves is one door's answer to a package whose shared job name no deployment runs a job of (with scheduled work on the binder refuses it at bind; with it off, the default, no job of the package is scheduled). Skills-docs: follow-up #32896 — content/docs/automation/jobs.mdx (its job-name paragraph and its install callout say the runtime refuses a shared name at bind; one sentence owed: `os package install` refuses such a package with `422` before installing, and the installed version keeps running). `skills/**` does not teach the install door's job refusals. ## 维护者速读 - 改了什么:通过 install-local(`os package install`)装一个包,若包里有两个及以上同名且启用的定时任务,以前门口答 200,之后看部署:定时调度默认关(`OS_AUTOMATION_SCHEDULED_WORK_ENABLED` 未设)或没有 job 服务时,包整个装上、登记记账,任务按开关一个都不调度,名字没人判,升级也落到新版本;开了调度时,绑定器拒绝这个名字、一个都不调度,还把旧版本正在跑的同名任务取消了。现在不论开关,门口都直接 422 拒收(与开关关着时照样拒收没有 body 的任务一致),提示里原样引用绑定器的拒绝句(每个任务、每个声明它的包、以及制品顶层 residual),什么都不写入。 - 为什么改:开了调度的部署上,运维看到"安装成功",实际这些任务都不跑、旧任务也停了,毫无提示;默认(调度关)的部署上,这个名字要等开了调度才在绑定时被拒(#32411 契约审查点名的余项,专题 #31527)。 - 风险与回滚:只收窄一种以前就跑不起来的包;同名但禁用的孪生、名字各不相同的任务照旧安装。默认(调度关)的部署上,以前整包装上(任务本就不跑)的这种包或这种升级,现在整包被拒。已装包重启照旧加载(开着调度时绑定器照旧拒绝并记 error,关着时任务照旧不调度)。回滚即 revert。 - 先看:`packages/cloud-connection/src/marketplace-install-local-plugin.ts` 的 `unrunnableCode`(新判定的懒加载与降级告警)和 `describeUnrunnable` 的新首句;`packages/runtime/src/app-artifact-handlers.ts` 的 `collectJobNameCollisions`(只是 `jobNameCollisions` 的出口)。 - 两分钟验证:`pnpm --filter @objectstack/cloud-connection exec vitest run --maxWorkers=2 src/marketplace-install-local-jobs.test.ts -t 32572`,应见 6 passed(main 源码下 4 个拒收钉子红、2 个 CONTROL 绿)。 - 需要你做的:无,席位落地。 ## What changes **The defect.** Since #32563 the binder (`scheduleAppArtifactJobs`), on a deployment that runs package-authored scheduled work, refuses a job name two or more enabled jobs of one artifact share (`jobNameCollisions`): the job service keys a job by its name and keeps only the last one scheduled, so none of the name's jobs is scheduled, the refusal is logged at `error`, and the job of that name the app scheduled before is cancelled. With scheduled work off (`OS_AUTOMATION_SCHEDULED_WORK_ENABLED` unset, the default in every posture) or with no `job` service, the binder returns before it judges any name: every job is withheld (one `info` or `warn` line) and nothing is refused. The install-local door pre-judges the jobs it cannot run (`collectJobsWithoutBody`) whatever the switch, but not a shared name, so it answered such a package `200` on every deployment: with the switch on, an upgrade stopped the job the installed version ran; with it off, the package (or an upgrade to it) installed whole, carrying a name the binder refuses as soon as scheduled work is turned on. **The fix.** 1. **`@objectstack/runtime` (`app-artifact-handlers.ts`, `index.ts`).** New export `collectJobNameCollisions(bundle, appId): PackageScopedRefusal[]` = `jobNameCollisions(bundle, appId, collectBundleJobs(bundle))` — the bind's own judgement over the jobs the binder reads, one refusal per shared name, in the order the binder logs them. Not a second copy: the binder and the door call the same function. `scheduleAppArtifactJobs`'s docblock says install-local now refuses the shape up front. 2. **`@objectstack/cloud-connection` (`marketplace-install-local-plugin.ts`).** The install route's step 1d (code this door cannot run) also judges shared names: `unrunnableCode` resolves `collectJobNameCollisions` lazily from `@objectstack/runtime`, as it resolves the other two judgements, and calls it with `manifestId` — the id `bindArtifactHandlers` schedules the package's jobs under. A runtime that predates the export judges nothing and says so at `warn`, as for the other two. `describeUnrunnable` gains a first clause (first because the binder judges the name before any job's run form) that quotes each refusal's `message` whole, so the jobs and their holders are the bind's own words: every declaring package body, and — when the artifact holds more jobs of the name than its bodies declare — `this artifact's top level outside every package body (its residual, …)`. **Why a refusal, not a report in the answer.** It is how this door already answers every job it cannot run: a job with no `body`, a `body` the declaration refuses, a `pull` that does not bind — one `422 VALIDATION_ERROR` before any write, one clause per kind, so the author fixes them in one pass. A shared name is the same kind of fact (installed, the jobs would never be scheduled), and, with scheduled work on, refusing it before any write is what keeps the installed version's job running on an upgrade; a 200 with a report would still cancel it. The answer stays prose-only like the other clauses: the unrunnable refusal carries no `details`, and adding one would also move `@objectstack/client`'s `err.details` from the whole body to that object (a second narrowing face). The holder vocabulary is the bind's by construction, since its message is quoted. **Not changed.** The `kernel:ready` rehydrate is not gated (as for the other 1d judgements): an entry installed before loads, and its jobs are bound as today (with scheduled work on its shared name is refused at bind; with it off every job is withheld). The binder's judgement, its `409` log line and its candidates are untouched. The `unmanaged` mode passes through the same step 1d, as the other judgements do. ## FROM → TO (every moved answer) FROM = `origin/main` `c04aa295` (source of the three changed files restored over the fix, runtime rebuilt), measured by the pins below. The pins run with scheduled work on (the test harness sets `OS_AUTOMATION_SCHEDULED_WORK_ENABLED` to `true`), so the rows marked **on** are pinned; the rows marked **off** and the no-job-service row are the contract review's probe A readings (6838806726), reproduced by the epic red-line read (6839378150), and are not pinned here. The multi-package, one-pass and CONTROL rows are with scheduled work on. | Install-local request | FROM | TO | |:--|:--|:--| | single-package artifact, two enabled body jobs `jobs_app_twin` (plus one of its own name); scheduled work **on** | `200`, `hotLoaded: true`; the binder refuses `jobs_app_twin` at `error` and schedules only the other job | `422 VALIDATION_ERROR`; message names the shared name and quotes the bind refusal (`declared by package "com.example.jobsapp", the app itself — one that runs a sandboxed body, and one that runs a sandboxed body`); nothing registered, persisted or scheduled | | the same package, scheduled work **off** (`OS_AUTOMATION_SCHEDULED_WORK_ENABLED` unset, the default) | `200`; the package registered and recorded in the ledger, no job scheduled (one `info` line: declarative jobs not scheduled), nothing refused, no `error` line | `422 VALIDATION_ERROR`, the same message; nothing registered | | the same package, scheduled work on but no `job` service | `200`; the package registered, one `warn` line (job service not registered), nothing refused | `422 VALIDATION_ERROR`; nothing registered | | upgrade, scheduled work **on**: v1 with one `jobs_app_twin` installed and scheduled, then the package declaring it twice | `200`, `upgradedFrom` set; the bind refuses the name and cancels the running `jobs_app_twin` (the runtime pin `a refused name cancels the job of that name an earlier install of the package scheduled`) | `422 VALIDATION_ERROR`; no cancel, `jobs_app_twin` still scheduled, the ledger keeps v1 | | upgrade, scheduled work **off**: v1 with one `jobs_app_twin` installed (its jobs withheld), then the package declaring it twice | `200`, the ledger at v2 (`0.2.0`); no job scheduled, nothing refused | `422 VALIDATION_ERROR`; the ledger keeps v1 (`0.1.0`) | | multi-package artifact (`composeStacks`, `manifest: 'preserve'`): body `com.example.jobsalpha` and the residual both carry `jobs_app_twin` | `200` | `422`; quotes `declared by package "com.example.jobsalpha"; and by this artifact's top level outside every package body (its residual, which runs as package "com.example.jobsapp", the body that carries the artifact's id)` | | shared name beside a handler-only job | `422`, the no-`body` clause only | `422`, the shared-name clause first, then the no-`body` clause | | CONTROL: two enabled jobs of distinct names | `200`, both scheduled | unchanged | | CONTROL: an enabled job and a DISABLED twin of its name | `200`, the enabled one scheduled | unchanged | The binder's own answers (log line, `409 RESOURCE_CONFLICT` error, candidates, `refused` / `cancelled`) do not move; `collectJobNameCollisions` answers exactly what it logs (runtime pin below). ## Tests - `packages/cloud-connection/src/marketplace-install-local-jobs.test.ts` — new top-level describe `[#32572] install-local refuses a package with two enabled jobs of one name, as the binder refuses it at bind` (the file's existing harness: the real `@objectstack/runtime` dist binder): the refusal (422, code, the quoted bind sentence, nothing registered / persisted / scheduled / written), the upgrade (no cancel, installed job keeps running, ledger keeps v1), the multi-package residual holder, one answer naming the shared name beside a no-`body` job, and two CONTROLs (distinct names; a disabled twin). - `packages/runtime/src/app-artifact-handlers.job-pull.test.ts` — new top-level describe `[#32572] collectJobNameCollisions answers the refusals the binder refuses a shared job name by`: for three arrangements (body + residual running as no declaring body; body + residual running as that body; one package listing two names twice) the export deep-equals the refusals the binder logs on a real `CronJobAdapter`; CONTROLs (distinct names, a disabled twin) answer none and the binder refuses none. <details><summary>Red / green / ablation</summary> | Run | Tree | cloud-connection jobs file | |:--|:--|:--| | red (FROM) | the three source files at `origin/main` `c04aa295`, runtime rebuilt (dist has no `collectJobNameCollisions`), pins of this PR | 4 failed / 19 passed — the four refusal pins (`expected 200 to be 422` ×3; the one-pass pin lacks the shared-name clause); both CONTROLs green | | green | `0fbfde90` (the fix; the merge `487a0f5b` brings two commits touching neither package) | 23 / 23 | | ablation | `node scripts/ablation-replace.mjs --file packages/cloud-connection/src/marketplace-install-local-plugin.ts --anchor 'collectShared(manifest, manifestId).map(({ name, message }) => ({ name, message }))' --replacement '[] /* ABLATE_32572 */' -- …` | anchor x1 → x0, marker x0 → x1; 4 failed / 19 passed (the same four), CONTROLs green; restored: blob f91ccdc == HEAD, `git diff HEAD` empty | The cloud-connection file imports the plugin from source and the runtime through its `exports` (built `dist/`), so the door-side ablation needs no rebuild; the red leg rebuilt the runtime from `main`'s source, and the green and ablation legs ran on a runtime dist rebuilt from HEAD (`grep -c collectJobNameCollisions packages/runtime/dist/index.js` = 2). </details> <details><summary>Suites and typecheck</summary> On `0fbfde90` (the merge to `487a0f5b` adds #32804 and #32824, which touch `packages/rest` and `ui/` only, so per AGENTS.md §10 these were not re-run): - `pnpm --filter @objectstack/runtime test` :: exit 0 — 588 files, 10255 passed / 19 skipped - `pnpm --filter @objectstack/cloud-connection test` :: exit 0 — 80 files, 1203 passed - `pnpm --filter @objectstack/runtime typecheck` :: exit 0 (`NODE_OPTIONS=--max-old-space-size=8192`) - `pnpm --filter @objectstack/cloud-connection typecheck` :: exit 0 - `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/app-artifact-handlers.job-pull.test.ts` :: exit 0 — 64 passed </details> ## Verification On `487a0f5b` (main `5c0f1134` merged once, before this PR; the final head `ee4577cf` adds one text-only commit to the changeset, see the last bullet): - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 70 derived; each run, exit code captured before any pipe: **70 / 70 exit 0**. Three first answered exit 3 (a prerequisite, not a verdict) and were re-run once it was met: `check-plugin-teardown-shape.mjs --self-test` (its pinned fixture commit fetched into the shallow clone; 48 cases pass), `pnpm check:dual-build-cjs-loads` (the nine dists the dogfood closure does not build, built; 123 entries / 72 packages load), `pnpm check:type-check-debt` (re-run under the verify lock after the dogfood battery released it; 0 entries above their record). - `node scripts/pm/dispatch-gates.mjs --ran`: 70 derived, 70 run, 0 NOT-MEASURED, 0 UNRUN. - `pnpm lint` :: exit 0. - **Dogfood battery** (owed: `!` title and a `(narrowing)` arm): closure `pnpm exec turbo run build --filter='@objectstack/dogfood^...'` rebuilt on `487a0f5b`, then `pnpm --filter @objectstack/dogfood test` under `os-verify-lock.sh`, no shard, no path: VERDICT command-exit 0 — Test Files 456 passed / 3 skipped (459), Tests 3831 passed / 42 skipped (3873). - CI check-runs: cited by the seat at ACCEPT (this body was written at create; r2 amends the S2 lines only). - **r2, final head `ee4577cf`** (the changeset's text only, for the red-line read's S2): per AGENTS.md §10 only the gates that read a changeset were re-run, base `origin/main` = merge base `5c0f1134`, each exit code captured before any pipe: `node scripts/check-adr-0087-registration.mjs --base origin/main` :: exit 0 (read as `[BREAKING+bang+clause-②-narrowing] not-required (no-migration-prescription)`); `node scripts/check-adr-0087-registration.mjs --self-test` :: exit 0; `node scripts/check-changeset-no-major.mjs --base origin/main` :: exit 0; `node scripts/check-empty-changeset.mjs --base origin/main` :: exit 0; `node scripts/check-empty-changeset.mjs --self-test` :: exit 0; `pnpm check:changeset-gate-self-tests` :: exit 0. No main merge; code and pins unchanged since `487a0f5b`, so the suites, the 70 gates and the dogfood battery above stand. ## Acceptance notes - File surface: the claim names `packages/cloud-connection/src/**`, `packages/runtime/src/app-artifact-handlers.ts`, their tests and the changeset. This diff also edits `packages/runtime/src/index.ts` (+3 lines: the export and its comment), the one way the door can reach the shared judgement through `@objectstack/runtime`'s entry; no other file outside the surface. - `Clause-②` measured `yes (narrowing)` (claim expected `no (narrowing)`): the new runtime export is the widening face. A `no` would need the door to carry its own copy of the judgement, which the card asks to avoid. - Docs: `content/docs/automation/jobs.mdx` owes one sentence (see `Skills-docs:`); left out of this diff because the claim's file surface does not name it. - Branch is the platform-assigned `claude/project-thread-5ff19y` (not `claude/issue-32572-*`), from `origin/main` `c04aa295`; `origin/main` `5c0f1134` merged once, before this PR (`487a0f5b`); later merges only on a conflict, a main-caused red or a queue kick. - r2 (epic red-line read 6839378150, HOLD on the contract review's S2, text only): the changeset's Before bullet (now one bullet for scheduled work off, the default, and one for on), its `Clause-②` line, its Now and Who moves bullets and its ADR-0087 marker's reason, and this body's matching lines (`Clause-②:`, `Metadata-protocol:`, 维护者速读, The defect, Why a refusal, Not changed, and the single-package and upgrade rows of FROM → TO) now state both deployments. `Clause-②` stays `yes (narrowing)`. Code and pins are unchanged since `487a0f5b`; S1, F1 and the nits ride #32913. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (spec untouched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgTHn5TtkSoqxQzSJ34)_ <!-- signed: domain:server#7 · os-sales · session_01L6bhgVSjQBHNkZd6Eqx2XX --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 64b46fe commit ade13d3

6 files changed

Lines changed: 267 additions & 11 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@objectstack/cloud-connection': patch
3+
'@objectstack/runtime': patch
4+
---
5+
6+
fix(cloud-connection, runtime)!: install-local refuses a package with two enabled jobs of one name, as the binder refuses the name at bind
7+
8+
Clause-②: yes (narrowing) — the install-local install route (`POST /api/v1/marketplace/install-local`) refuses a package with two or more enabled jobs of one name with `422 VALIDATION_ERROR`, where it answered `200` and none of those jobs ran: on a deployment that runs package-authored scheduled work the binder then refused the name at bind, and on one that does not (the default) the package installed with every job withheld. The door judges the package whatever the deployment's scheduled-work switch, as it already judges a job with no `body`. The widening half: `@objectstack/runtime` exports `collectJobNameCollisions(bundle, appId)`, the binder's own judgement of a shared job name, which the door refuses by.
9+
Metadata-protocol: none
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and nothing at rest moves: what moves is the install door's answer to a package whose enabled jobs share a name, a name no deployment runs a job of: with scheduled work on the binder refuses it at bind, and with scheduled work off (the default) no job of the package is scheduled at all. A package installed before keeps rehydrating, and its jobs are bound as before (withheld with scheduled work off, the shared name refused at bind with it on), so there is nothing for a migration to rewrite. -->
12+
13+
**BREAKING** accept-set narrowing at the install-local door (`@objectstack/cloud-connection`): a package whose enabled jobs share a name is refused instead of installed.
14+
15+
- **Before, scheduled work off (the default).** `os package install` (and any client of `POST /api/v1/marketplace/install-local`) answered `200` for a package declaring two enabled jobs of one name. With `OS_AUTOMATION_SCHEDULED_WORK_ENABLED` unset, as in every posture by default, or with no job service registered, the binder judges no job name: the package was registered and recorded in the ledger whole, every job of it was withheld (one `info` line, or a `warn` line without a job service), nothing was refused, and an upgrade to such a version landed. The shared name was refused only once the deployment turned scheduled work on, at bind.
16+
- **Before, scheduled work on.** The same request answered `200`, and the binder then refused the name at `error` (the job service keys a job by its name and would keep only the later one): none of those jobs was scheduled, and the job of that name the previously installed version ran was cancelled. The door said the install succeeded.
17+
- **Now.** The install is refused with `422 VALIDATION_ERROR`, the refusal this door gives every job it cannot run, before anything is registered, persisted or scheduled, whatever the deployment's scheduled-work switch (as this door already refuses a job with no `body` with the switch off). The installed version stays installed and recorded, and with scheduled work on its jobs keep running. The message quotes the binder's own refusal of the name: every job of it by how it runs, and every holder that declares it — each package body, and the artifact's top level outside every package body (its residual) when that carries the name too. A disabled twin collides with nothing and installs as before, and so do jobs of distinct names.
18+
- **Who moves.** An author whose package declares one job name twice among its enabled jobs, on every deployment. With scheduled work off (the default) such a package, or an upgrade to such a version, installed whole with its jobs withheld, and is now refused whole. A package installed before this release still loads after a restart, and its jobs are bound as before: withheld with scheduled work off, its shared name refused at bind and logged with it on.
19+
20+
**The remedy.** Rename all but one of the jobs so each job name is declared once in the artifact, or set `enabled: false` on the ones that should not run, then install again.
21+
22+
`collectJobNameCollisions(bundle, appId)` (`@objectstack/runtime`): the job names two or more enabled jobs of `bundle` share, each with the `PackageScopedRefusal` the binder (`scheduleAppArtifactJobs`) refuses it by when it schedules the artifact as `appId`. A door that pre-judges a package reads it so it cannot disagree with the binder.

‎packages/cloud-connection/src/marketplace-install-local-jobs.test.ts‎

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
* entry an earlier build persisted rehydrates with its unbindable pull job
3232
* withheld and warned by name;
3333
* - a package without jobs, and one whose handler-only job is DISABLED,
34-
* install unchanged.
34+
* install unchanged;
35+
* - #32572: so is a package with two or more ENABLED jobs of one name,
36+
* naming the binder's own refusal of the name (every job, every holder);
37+
* an upgrade declaring it leaves the installed version's job running, and
38+
* distinct names or a DISABLED twin install as before.
3539
*
3640
* The binder is the REAL `@objectstack/runtime` export (resolved through its
3741
* `exports`, i.e. its built `dist/`, like the plugin's own lazy import), and so
@@ -48,6 +52,7 @@ import { tmpdir } from 'node:os';
4852
import '@objectstack/runtime';
4953
import { SCHEDULED_WORK_ENV } from '@objectstack/types';
5054
import { PROTOCOL_MAJOR } from '@objectstack/spec/kernel';
55+
import { composeStacks, defineStack } from '@objectstack/spec';
5156
import { MarketplaceInstallLocalPlugin } from './marketplace-install-local-plugin.js';
5257
import { installerAuthService, withInstallerGrants } from './install-local-principal.fixtures.js';
5358
import { LocalManifestSource } from './local-manifest-source.js';
@@ -505,3 +510,112 @@ describe('install-local refuses an enabled job whose pull does not bind, by the
505510
expect(String(warned![0])).toContain("pull.mapping: this artifact declares no mapping 'orders_pul'");
506511
});
507512
});
513+
514+
/**
515+
* [#32572, ADR-0150 D3] Two or more ENABLED jobs of one name. The binder refuses the name at bind
516+
* (`scheduleAppArtifactJobs`, its `jobNameCollisions`): the job service keys a job by its name and would keep
517+
* only the later, so none of the name's jobs is scheduled, and a job of the name an earlier version scheduled
518+
* is cancelled. This door answered such a package 200. It now refuses it as it refuses every other job it
519+
* cannot run — `422 VALIDATION_ERROR`, before anything is registered, persisted or scheduled — quoting the
520+
* binder's own refusal (`collectJobNameCollisions`): every job of the name, and its holders, the residual
521+
* by its own words included. A disabled twin collides with nothing, as at bind.
522+
*/
523+
describe('[#32572] install-local refuses a package with two enabled jobs of one name, as the binder refuses it at bind', () => {
524+
const TWIN = { ...BODY_JOB, name: 'jobs_app_twin' };
525+
const TWIN_SLOW = { ...TWIN, schedule: { type: 'interval', intervalMs: 5000 } };
526+
const OTHER = { ...BODY_JOB, name: 'jobs_app_other' };
527+
528+
it('answers 422 VALIDATION_ERROR naming the name, both jobs and their holder — and changes nothing', async () => {
529+
const { install, rec, jobs, register } = await bootPlugin();
530+
531+
const res = await install(artifact([TWIN, TWIN_SLOW, OTHER]));
532+
533+
expect(res.status, JSON.stringify(res.payload)).toBe(422);
534+
expect(res.payload.success).toBe(false);
535+
expect(res.payload.error.code).toBe('VALIDATION_ERROR');
536+
const message: string = res.payload.error.message;
537+
expect(message).toContain(`two or more of its enabled jobs share the name '${TWIN.name}'`);
538+
// The binder's own refusal, quoted: both jobs by their run form, the holder in the bind's words.
539+
expect(message).toContain(`The artifact holds 2 enabled jobs named "${TWIN.name}", declared by package "${APP_ID}"`);
540+
expect(message).toContain('one that runs a sandboxed body, and one that runs a sandboxed body');
541+
expect(message).toContain('Rename all but one of them');
542+
// The job of a name of its own is no part of the refusal.
543+
expect(message).not.toContain(OTHER.name);
544+
// The runtime is left exactly as it was found.
545+
expect(registered(register), 'a refused package must not be registered').toEqual([]);
546+
expect(new LocalManifestSource(dir).read(APP_ID).entry, 'nor persisted').toBeNull();
547+
expect(jobs.svc.schedule, 'nor any of its jobs scheduled — not even the job of a name of its own').not.toHaveBeenCalled();
548+
expect(rec.writes).toEqual([]);
549+
});
550+
551+
it('an upgrade whose new version declares the name twice is refused, and the job the installed version runs keeps running', async () => {
552+
const { install, jobs } = await bootPlugin();
553+
expect((await install(artifact([TWIN]))).status).toBe(200);
554+
expect([...jobs.scheduled.keys()]).toEqual([TWIN.name]);
555+
556+
const res = await install(artifact([TWIN, TWIN_SLOW]));
557+
558+
expect(res.status, JSON.stringify(res.payload)).toBe(422);
559+
expect(res.payload.error.code).toBe('VALIDATION_ERROR');
560+
expect(jobs.cancels, 'the installed version’s job must not be cancelled').toEqual([]);
561+
expect([...jobs.scheduled.keys()]).toEqual([TWIN.name]);
562+
const ledgered = new LocalManifestSource(dir).read(APP_ID).entry as { manifest?: { jobs?: unknown[] } } | null;
563+
expect(ledgered?.manifest?.jobs, 'the ledger keeps the installed version').toHaveLength(1);
564+
});
565+
566+
it('a multi-package artifact: the name a package body declares and the residual carries is refused, naming the body and the residual', async () => {
567+
const { install, jobs, register } = await bootPlugin();
568+
const SYNCED = { name: 'jobs_alpha_rec', label: 'Alpha record', fields: { name: { type: 'text', label: 'Name' } } };
569+
const alpha = defineStack({
570+
manifest: { id: 'com.example.jobsalpha', namespace: 'jobs_alpha', name: 'Jobs Alpha', version: '0.1.0', type: 'module' },
571+
objects: [SYNCED],
572+
jobs: [TWIN],
573+
} as never);
574+
// No `manifest`: its jobs reach the artifact's top level and no package body — the residual.
575+
const host = defineStack({ objects: [{ ...SYNCED, name: 'jobs_app_host_rec', label: 'Host record' }], jobs: [TWIN_SLOW] } as never);
576+
const bundle = JSON.parse(JSON.stringify(composeStacks([alpha, host, defineStack(artifact(undefined) as never)] as never[], { manifest: 'preserve' })));
577+
578+
const res = await install(bundle);
579+
580+
expect(res.status, JSON.stringify(res.payload)).toBe(422);
581+
expect(res.payload.error.code).toBe('VALIDATION_ERROR');
582+
const message: string = res.payload.error.message;
583+
expect(message).toContain(`two or more of its enabled jobs share the name '${TWIN.name}'`);
584+
expect(message).toContain('package "com.example.jobsalpha"');
585+
expect(message).toContain("this artifact's top level outside every package body (its residual");
586+
expect(registered(register)).toEqual([]);
587+
expect(jobs.svc.schedule).not.toHaveBeenCalled();
588+
});
589+
590+
it('one answer names the shared name beside a job with no body, so the author fixes both in one pass', async () => {
591+
const { install } = await bootPlugin();
592+
593+
const res = await install(artifact([TWIN, TWIN_SLOW, HANDLER_JOB]));
594+
595+
expect(res.status).toBe(422);
596+
const message: string = res.payload.error.message;
597+
expect(message).toContain(`share the name '${TWIN.name}'`);
598+
expect(message).toContain(`'${HANDLER_JOB.name}' (handler 'tick') has no \`body\``);
599+
});
600+
601+
it('CONTROL: two enabled jobs of distinct names install as today, and both are scheduled', async () => {
602+
const { install, jobs, register } = await bootPlugin();
603+
604+
const res = await install(artifact([TWIN, OTHER]));
605+
606+
expect(res.status, JSON.stringify(res.payload)).toBe(200);
607+
expect(registered(register)).toEqual([APP_ID]);
608+
expect([...jobs.scheduled.keys()].sort()).toEqual([OTHER.name, TWIN.name].sort());
609+
});
610+
611+
it('CONTROL: a DISABLED twin does not trigger the refusal — the package installs and its enabled job of the name is scheduled', async () => {
612+
const { install, jobs, register } = await bootPlugin();
613+
614+
const res = await install(artifact([TWIN, { ...TWIN_SLOW, enabled: false }]));
615+
616+
expect(res.status, JSON.stringify(res.payload)).toBe(200);
617+
expect(registered(register)).toEqual([APP_ID]);
618+
expect([...jobs.scheduled.keys()]).toEqual([TWIN.name]);
619+
expect(jobs.svc.schedule).toHaveBeenCalledTimes(1);
620+
});
621+
});

0 commit comments

Comments
 (0)