12
import { mkdirSync, readFileSync, writeFileSync, appendFileSync, existsSync, rmSync } from 'node:fs';
13
import { dirname, join, relative, resolve } from 'node:path';
14
import { fileURLToPath } from 'node:url';
15
-import { requireStagingBaseUrl, STAGING_BASE_URL } from './staging-backend.mjs';
15
+import { resolveBackendBaseUrl, STAGING_BASE_URL } from './backend-url.mjs';
16
17
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
18
const ARTIFACTS = join(ROOT, '.artifacts', 'examples-parity');
67
68
const baseUrl = () => {
69
try {
70
- return requireStagingBaseUrl();
70
+ return resolveBackendBaseUrl();
71
} catch (error) {
72
fail(error instanceof Error ? error.message : String(error));
73
}
315
return version;
316
};
317
318
+const PY_PROJECT = join(ROOT, 'python', 'pyproject.toml');
319
+const UV_LOCK = join(ROOT, 'uv.lock');
320
+const PY_CLIENT_PIN = /^(\s*)"composio-client==[^"]+",$/m;
321
+
322
+/**
323
+ * Drop the exact `composio-client==` pin from the python project.
324
+ *
325
+ * A candidate sweep layers the wheel onto every entry with `uv run --with`, but
326
+ * several entries also install the local `./python` project, whose exact pin the
327
+ * wheel contradicts — uv then refuses the whole overlay ("no solution found")
328
+ * and those entries go red for a packaging reason rather than a client one.
329
+ * Without the pin the wheel is the only `composio-client` in play. Baseline
330
+ * sweeps never call this, and restorePyBaseline() writes the pre-run files back
331
+ * either way.
332
+ */
333
+const relaxPyClientPin = (toml) => {
334
+ if (!PY_CLIENT_PIN.test(toml)) {
335
+ fail(`no exact composio-client pin found in ${relative(ROOT, PY_PROJECT)}`);
336
+ }
337
+ return toml.replace(PY_CLIENT_PIN, '$1"composio-client",');
338
+};
339
+
340
+const snapshotPyBaseline = () => snapshotFiles([PY_PROJECT, UV_LOCK]);
341
+
342
+const restorePyBaseline = async (snapshot) => {
343
+ restoreFiles(snapshot);
344
+ await sh(['uv', 'sync', '--project', 'python', '--frozen']);
345
+};
346
+
347
// --- llm mock ---------------------------------------------------------------
348
349
/** Start aimock serving harness/llm-mock/fixtures; resolve once it answers. */
394
mkdirSync(join(runDir, 'traces'), { recursive: true });
395
396
let tsBaselineSnapshot;
397
+ let pyBaselineSnapshot;
398
let stopLlmMock;
399
const pyWheel = process.env.COMPOSIO_CLIENT_WHEEL;
400
try {
411
if (!pyWheel) fail('candidate sweep with py entries needs COMPOSIO_CLIENT_WHEEL');
412
const v = await verifyPyCandidate(pyWheel);
413
console.log(`candidate composio-client (py) resolved: ${v}`);
414
+ pyBaselineSnapshot = snapshotPyBaseline();
415
+ writeFileSync(PY_PROJECT, relaxPyClientPin(readFileSync(PY_PROJECT, 'utf8')));
416
for (const e of entries) if (e.lang === 'py') e.pyWith = [...(e.pyWith ?? []), pyWheel];
417
}
418
}
434
} finally {
435
if (stopLlmMock) stopLlmMock();
436
if (tsBaselineSnapshot) await restoreTsBaseline(tsBaselineSnapshot);
437
+ if (pyBaselineSnapshot) await restorePyBaseline(pyBaselineSnapshot);
438
}
439
};
440
471
if (!ok) failures += 1;
472
};
473
441
- // 0. backend safety: the harness accepts only the canonical staging root.
442
- check('staging backend is accepted', requireStagingBaseUrl() === STAGING_BASE_URL);
443
- let productionRejected = false;
444
- try {
445
- requireStagingBaseUrl('https://backend.composio.dev');
446
- } catch {
447
- productionRejected = true;
448
- }
449
- check('production backend is rejected', productionRejected);
474
+ // 0. backend URL: staging is the default, any other bare https root is
475
+ // honoured as given, and anything structurally unusable is refused.
476
+ check('staging backend is the default', resolveBackendBaseUrl(undefined) === STAGING_BASE_URL);
477
+ check(
478
+ 'a non-staging bare https root is honoured',
479
+ resolveBackendBaseUrl('https://backend.composio.dev') === 'https://backend.composio.dev'
480
+ );
481
+ const refuses = (value) => {
482
+ try {
483
+ resolveBackendBaseUrl(value);
484
+ return false;
485
+ } catch {
486
+ return true;
487
+ }
488
+ };
489
+ check('a base URL carrying a path is refused', refuses('https://backend.composio.dev/api/v3'));
490
+ check('a base URL carrying a query is refused', refuses('https://backend.composio.dev/?x=1'));
491
+ check(
492
+ 'a base URL carrying credentials is refused',
493
+ refuses('https://user:pass@backend.composio.dev')
494
+ );
495
+ check('a plaintext base URL is refused', refuses('http://backend.composio.dev'));
496
+ check('an unparseable base URL is refused', refuses('not-a-url'));
497
498
let cleanupRan = false;
499
let cleanupError;
518
restoreFiles(cleanupSnapshot);
519
check('cleanup restores pre-run file contents', readFileSync(cleanupFixture, 'utf8') === 'user contents');
520
521
+ // The python candidate swap only resolves once the project's exact
522
+ // composio-client pin is out of the way; see relaxPyClientPin.
523
+ const pinnedProject = readFileSync(PY_PROJECT, 'utf8');
524
+ const relaxedProject = relaxPyClientPin(pinnedProject);
525
+ check('the python project pins composio-client exactly', /"composio-client==/.test(pinnedProject));
526
+ check(
527
+ 'relaxing the pin keeps composio-client a dependency',
528
+ /^\s*"composio-client",$/m.test(relaxedProject) && !/"composio-client==/.test(relaxedProject)
529
+ );
530
+ check(
531
+ 'relaxing the pin touches nothing else',
532
+ relaxedProject.replace(/^\s*"composio-client",$/m, '') ===
533
+ pinnedProject.replace(/^\s*"composio-client==[^"]+",$/m, '')
534
+ );
535
+ let unpinnedProjectRejected = false;
536
+ try {
537
+ relaxPyClientPin(relaxedProject);
538
+ } catch {
539
+ unpinnedProjectRejected = true;
540
+ }
541
+ check('relaxing an already-unpinned project is refused', unpinnedProjectRejected);
542
+
543
// 1. known-good: error-handling-demo (no backend, no keys).
544
const good = loadManifest().find((e) => e.id === 'ts/error-handling-demo/index');
545
const { env: goodEnv } = buildEnv(good, runDir);