Skip to content

Commit 2047273

Browse files
committed
test(service-automation,dogfood): pin the installed-package ref refusal; docs and changeset
Claude-Session: https://claude.ai/code/session_017xRBcVBKAFk1ntXSjvPt7U Co-authored-by: Claude <noreply@anthropic.com>
1 parent 54a3065 commit 2047273

4 files changed

Lines changed: 357 additions & 2 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
"@objectstack/service-automation": patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
fix(service-automation): an installed package's connector entry never reads the host's files
9+
10+
A connector entry declared by a package that was installed into the runtime (`os package install`,
11+
`POST /api/v1/marketplace/install-local`; the package registry's `source: 'marketplace'`) was handed
12+
`loadPackageFile` / `resolvePackagePath` anchored at the HOST's root, whichever package declared it. An installed
13+
package has no directory on the runtime it is installed into, so a relative ref resolved against another package's
14+
files: an installed `openapi` connector naming `./src/system/connectors/status-openapi.json` materialized `ready`
15+
with the showcase's own document, and a stdio `mcp` connector naming `./scripts/mcp-fixture.mjs` spawned the
16+
showcase's own fixture in the showcase's directory.
17+
18+
Both members now refuse every ref for such an entry, naming the entry, its package and the ref: a configuration
19+
fault, so the instance is not materialized and the reconcile logs the refusal. Fix by rebuilding the package with a
20+
current `os build`, which carries an `openapi` spec file into the artifact, or by inlining the document; an
21+
installed package reaches an MCP server over `http`, since a stdio transport needs a working directory inside the
22+
package. An entry carrying its document inline or as an `http(s)` URL is unaffected, and so is every entry of the
23+
host's own stack, which keeps reading its files as before.

‎content/docs/automation/connectors.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ retry):
793793
| The upstream refuses the credential (`401` / `403`), or an `mcp` server sent a static credential does not list a tool the instance's `include` names | **Not fatal**: the instance registers **degraded**. A stored credential is marked `rejected` and waits until it is set again (or a restart); an environment or vault credential is retried on the backoff |
794794
| Instance `name` collides with a plugin-registered connector | **Hard boot error** — there is no silent precedence between the two worlds |
795795
| stdio transport without host opt-in | **Hard boot error** with the `declarativeStdio` fix inline — a security rejection is never retried |
796+
| An entry of an **installed** package (`os package install`, `POST /api/v1/marketplace/install-local`) names a package-relative file — an `openapi` `spec` path — or needs a location inside its package, as a stdio `mcp` transport's working directory does | Configuration fault, **never resolved against the host's directory**: an installed package has no directory on the runtime it was installed into, and the host's is not its own. The instance is not materialized, and the reconcile's error names the entry, its package and the ref. Rebuild the package with a current `os build`, which carries an `openapi` spec file into the artifact, or inline the document; reach an MCP server from an installed package over `http`. The host's own entries keep reading their files |
796797
| MCP server unreachable / `tools/list` fails; remote spec URL unreachable or transiently failing (408/429/5xx) | **Not fatal**: the instance registers **degraded** (visible on `GET /api/v1/automation/connectors` with the reason), dispatches fail with that reason, and the platform retries on a 5s→5min backoff — recovery is automatic |
797798
| A retry of a degraded instance reaches the upstream and meets a configuration fault (an `include` naming a tool or operation the upstream does not offer; on an `mcp` instance that sends a static credential, the credential row above applies instead) | **Not fatal**: the instance stays **degraded**, now with the configuration reason, and is **not retried** — dispatches fail saying to edit its declaration; an edit of the entry (or a restart) re-attempts it |
798799
| Wrong spec URL (other 4xx) or unparseable document | Configuration fault — **hard boot error** |
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// GOLDEN REGRESSION — a connector entry an INSTALLED package declares never
4+
// reads, or launches a process in, the HOST's package root (#28534).
5+
//
6+
// ## What was measured before the fix
7+
//
8+
// Installed into the showcase through `POST /api/v1/marketplace/install-local`,
9+
// an inline manifest whose `provider: 'openapi'` connector names
10+
// `providerConfig.spec: './src/system/connectors/status-openapi.json'` — a file
11+
// the installed package does not ship, and the showcase does — materialized
12+
// `ready` on `GET /api/v1/automation/connectors` carrying the showcase's own
13+
// document: its description and its `getHealth` action. A `provider: 'mcp'`
14+
// stdio connector naming `./scripts/mcp-fixture.mjs` spawned the showcase's own
15+
// fixture, its working directory the showcase's root, and listed `ready` with
16+
// the fixture's `echo_upper` tool. The materializer handed every entry the
17+
// host's root as `loadPackageFile` / `resolvePackagePath`, whichever package
18+
// declared it; an installed package has no root on disk at all, since the
19+
// install keeps its artifact JSON and nothing else.
20+
//
21+
// ## What this file pins, on one boot
22+
//
23+
// 1. the install answers 200 and hot-loads the package;
24+
// 2. neither installed entry that names a package-relative ref materializes:
25+
// both are absent from the listing, and the reconcile's error record names
26+
// each entry, its ref and the remedy;
27+
// 3. controls: the installed entry carrying its document inline lists
28+
// `ready` with that document's operation, and the showcase's own
29+
// file-ref and stdio entries keep listing `ready` with their own actions.
30+
//
31+
// Boots a fixture stack of its own (the install-local plugin mounted), so it
32+
// stays out of `SHARED_SHOWCASE`.
33+
34+
import { mkdtempSync, rmSync } from 'node:fs';
35+
import { tmpdir } from 'node:os';
36+
import { join } from 'node:path';
37+
38+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
39+
import { type VerifyStack } from '@objectstack/verify';
40+
import { MarketplaceInstallLocalPlugin } from '@objectstack/cloud-connection';
41+
import { bootShowcase } from './showcase-boot.js';
42+
43+
const PACKAGE_ID = 'com.dogfood.pkgref';
44+
/** An `openapi` entry naming a file the showcase ships and the installed package does not. */
45+
const FILE_REF_ENTRY = 'pkgref_host_file';
46+
const FILE_REF = './src/system/connectors/status-openapi.json';
47+
/** A stdio `mcp` entry whose working directory the provider asks for with `resolvePackagePath('.')`. */
48+
const PATH_REF_ENTRY = 'pkgref_host_cwd';
49+
/** Control: an installed `openapi` entry carrying its document inline. */
50+
const INLINE_ENTRY = 'pkgref_inline';
51+
/** The showcase's own entries — the file-ref and stdio forms of the same two providers. */
52+
const HOST_FILE_ENTRY = 'showcase_status_openapi';
53+
const HOST_STDIO_ENTRY = 'showcase_mcp_tools';
54+
55+
/** A one-operation OpenAPI 3 document; nothing is dispatched, so its server answers nothing. */
56+
const DOCUMENT = {
57+
openapi: '3.0.3',
58+
info: { title: 'Installed inline document', version: '1.0.0' },
59+
servers: [{ url: 'http://127.0.0.1:9/' }],
60+
paths: { '/v1/things': { get: { operationId: 'GetThings', responses: { '200': { description: 'ok' } } } } },
61+
};
62+
63+
/** The install body `os package install` sends for an inline manifest. */
64+
const INSTALL_BODY = {
65+
manifest: {
66+
id: PACKAGE_ID,
67+
namespace: 'pkgref',
68+
name: 'Installed package-relative connector refs',
69+
version: '1.0.0',
70+
type: 'app',
71+
connectors: [
72+
{
73+
name: FILE_REF_ENTRY,
74+
label: 'Names a host file',
75+
type: 'api',
76+
provider: 'openapi',
77+
providerConfig: { spec: FILE_REF, baseUrl: 'http://127.0.0.1:9/' },
78+
},
79+
{
80+
name: PATH_REF_ENTRY,
81+
label: 'Runs in the host root',
82+
type: 'api',
83+
provider: 'mcp',
84+
providerConfig: { transport: { kind: 'stdio', command: 'node', args: ['./scripts/mcp-fixture.mjs'] } },
85+
},
86+
{
87+
name: INLINE_ENTRY,
88+
label: 'Inline document',
89+
type: 'api',
90+
provider: 'openapi',
91+
providerConfig: { spec: DOCUMENT },
92+
},
93+
],
94+
},
95+
};
96+
97+
type Answer = { status: number; body: any };
98+
99+
async function json(res: Response): Promise<Answer> {
100+
return { status: res.status, body: await res.json().catch(() => null) };
101+
}
102+
103+
/** Every line the process writes while `run` is in flight — the kernel logger writes to the streams. */
104+
async function captureOutput<T>(run: () => Promise<T>): Promise<{ value: T; lines: string[] }> {
105+
const lines: string[] = [];
106+
const stdout = process.stdout.write.bind(process.stdout);
107+
const stderr = process.stderr.write.bind(process.stderr);
108+
const warn = console.warn;
109+
const error = console.error;
110+
(process.stdout as any).write = (chunk: unknown, ...rest: any[]) => { lines.push(String(chunk)); return stdout(chunk as any, ...rest); };
111+
(process.stderr as any).write = (chunk: unknown, ...rest: any[]) => { lines.push(String(chunk)); return stderr(chunk as any, ...rest); };
112+
console.warn = (...args: unknown[]) => { lines.push(args.map(String).join(' ')); warn(...args); };
113+
console.error = (...args: unknown[]) => { lines.push(args.map(String).join(' ')); error(...args); };
114+
try {
115+
return { value: await run(), lines };
116+
} finally {
117+
(process.stdout as any).write = stdout;
118+
(process.stderr as any).write = stderr;
119+
console.warn = warn;
120+
console.error = error;
121+
}
122+
}
123+
124+
const listed = (answer: Answer): any[] => answer.body?.data?.connectors ?? [];
125+
const entryOf = (answer: Answer, name: string): any => listed(answer).find((c: any) => c?.name === name);
126+
/** What a listing says about one entry — enough for a failure to show whose document it carried. */
127+
const shown = (answer: Answer, name: string): string => {
128+
const c = entryOf(answer, name);
129+
return c === undefined
130+
? `'${name}' not listed`
131+
: JSON.stringify({ name: c.name, state: c.state, description: c.description, actions: c.actions?.map((a: any) => a.key) });
132+
};
133+
134+
describe('dogfood: an installed package\'s package-relative connector ref is refused, never resolved against the host\'s root', () => {
135+
let stack: VerifyStack;
136+
let storageDir: string;
137+
let install: Answer;
138+
let connectors: Answer;
139+
let lines: string[] = [];
140+
141+
beforeAll(async () => {
142+
storageDir = mkdtempSync(join(tmpdir(), 'dogfood-connector-package-ref-'));
143+
stack = await bootShowcase({
144+
extraPlugins: [new MarketplaceInstallLocalPlugin({ controlPlaneUrl: 'off', storageDir })],
145+
});
146+
const token = await stack.signIn();
147+
const captured = await captureOutput(async () => {
148+
install = await json(await stack.apiAs(token, 'POST', '/marketplace/install-local', INSTALL_BODY));
149+
// The reconcile the install's re-sync announces may land after the
150+
// answer: read the listing until the inline control is in it, or the
151+
// window closes. The control and the refused entries are judged in the
152+
// same reconcile run.
153+
const deadline = Date.now() + 10_000;
154+
do {
155+
connectors = await json(await stack.apiAs(token, 'GET', '/automation/connectors'));
156+
if (entryOf(connectors, INLINE_ENTRY)) break;
157+
await new Promise((r) => setTimeout(r, 100));
158+
} while (Date.now() < deadline);
159+
});
160+
lines = captured.lines;
161+
}, 300_000);
162+
163+
afterAll(async () => {
164+
await stack?.stop?.();
165+
if (storageDir) rmSync(storageDir, { recursive: true, force: true });
166+
});
167+
168+
it('the install answers 200 and hot-loads the package', () => {
169+
expect(install.status, JSON.stringify(install.body)).toBe(200);
170+
expect(install.body?.data?.hotLoaded).toBe(true);
171+
expect(connectors.status, JSON.stringify(connectors.body)).toBe(200);
172+
});
173+
174+
it('controls: the installed inline entry and the showcase\'s own file-ref and stdio entries list ready', () => {
175+
expect(entryOf(connectors, INLINE_ENTRY)?.state, shown(connectors, INLINE_ENTRY)).toBe('ready');
176+
expect(entryOf(connectors, INLINE_ENTRY).actions.map((a: any) => a.key)).toEqual(['GetThings']);
177+
expect(entryOf(connectors, HOST_FILE_ENTRY)?.state, shown(connectors, HOST_FILE_ENTRY)).toBe('ready');
178+
expect(entryOf(connectors, HOST_FILE_ENTRY).actions.map((a: any) => a.key)).toEqual(['getHealth']);
179+
expect(entryOf(connectors, HOST_STDIO_ENTRY)?.state, shown(connectors, HOST_STDIO_ENTRY)).toBe('ready');
180+
});
181+
182+
it('the installed entry naming a host FILE does not materialize, and the record names it, its ref and the remedy', () => {
183+
expect(entryOf(connectors, FILE_REF_ENTRY), shown(connectors, FILE_REF_ENTRY)).toBeUndefined();
184+
const record = lines.find((l) => l.includes(`connector instance '${FILE_REF_ENTRY}'`) && l.includes(PACKAGE_ID));
185+
expect(record, `no reconcile record names '${FILE_REF_ENTRY}' with its package`).toBeDefined();
186+
expect(record).toContain(`'${FILE_REF}'`);
187+
expect(record).toContain('os build');
188+
});
189+
190+
it('the installed entry asking for a host LOCATION does not materialize, and the record names it and its ref', () => {
191+
expect(entryOf(connectors, PATH_REF_ENTRY), shown(connectors, PATH_REF_ENTRY)).toBeUndefined();
192+
const record = lines.find((l) => l.includes(`connector instance '${PATH_REF_ENTRY}'`) && l.includes(PACKAGE_ID));
193+
expect(record, `no reconcile record names '${PATH_REF_ENTRY}' with its package`).toBeDefined();
194+
expect(record).toContain('path ref \'.\'');
195+
});
196+
});

0 commit comments

Comments
 (0)