Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "1.0.38",
"version": "1.0.41",
"type": "module",
"bin": {
"spawn": "cli.js"
Expand Down
25 changes: 25 additions & 0 deletions packages/cli/src/__tests__/feature-flags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { dirname, join } from "node:path";
import {
_awaitBackgroundRefreshForTest,
_resetFeatureFlagsForTest,
expandFastProvisionVariant,
getFeatureFlag,
initFeatureFlags,
} from "../shared/feature-flags.js";
Expand Down Expand Up @@ -225,4 +226,28 @@ describe("feature flags", () => {
expect(getFeatureFlag("unknown", "default")).toBe("default");
});
});

describe("expandFastProvisionVariant", () => {
// These tests pin the experiment bundle composition so that tweaking the
// list in feature-flags.ts forces an explicit test update — drifting the
// bundle silently is the failure mode we're guarding against.

it("returns the full provisioning-speed bundle for the test variant", () => {
expect(expandFastProvisionVariant("test")).toEqual([
"images",
"docker",
"sandbox",
]);
});

it("returns an empty bundle for the control variant", () => {
expect(expandFastProvisionVariant("control")).toEqual([]);
});

it("returns an empty bundle for unknown variants (fail-closed)", () => {
expect(expandFastProvisionVariant("")).toEqual([]);
expect(expandFastProvisionVariant("rollout")).toEqual([]);
expect(expandFastProvisionVariant("totally-made-up")).toEqual([]);
});
});
});
13 changes: 8 additions & 5 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
} from "./commands/index.js";
import { expandEqualsFlags, findUnknownFlag } from "./flags.js";
import { agentKeys, cloudKeys, getCacheAge, loadManifest } from "./manifest.js";
import { getFeatureFlag, initFeatureFlags } from "./shared/feature-flags.js";
import { expandFastProvisionVariant, getFeatureFlag, initFeatureFlags } from "./shared/feature-flags.js";
import { getInstallRefPath } from "./shared/paths.js";
import { asyncTryCatch, asyncTryCatchIf, isFileError, isNetworkError, tryCatch, tryCatchIf } from "./shared/result.js";
import { captureError, initTelemetry, setTelemetryContext } from "./shared/telemetry.js";
Expand Down Expand Up @@ -969,13 +969,16 @@ async function main(): Promise<void> {

// fast_provision experiment: if the user did NOT pass --beta or --fast,
// bucket them on the PostHog `fast_provision` flag. The `test` variant
// turns on images by default; control behaves as before.
// turns on images + docker + sandbox by default; control behaves as before.
// - images: pre-built DO marketplace images (cloud-side faster boot)
// - docker: Docker CE host image on Hetzner/GCP (cloud-side faster boot)
// - sandbox: local agents run in a Docker container (local-side faster boot)
// Exposure is captured for both variants so PostHog can compute conversion.
// Bundle composition lives in expandFastProvisionVariant() for unit testing.
if (!userOptedIntoBeta) {
const variant = getFeatureFlag("fast_provision", "control");
if (variant === "test") {
betaFeatures.push("images");
}
const variantStr = isString(variant) ? variant : "control";
betaFeatures.push(...expandFastProvisionVariant(variantStr));
}

if (betaFeatures.length > 0) {
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/src/shared/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,26 @@ export function getFeatureFlag<T extends string | boolean>(key: string, fallback
return value;
}

/**
* Beta features bundled by the `fast_provision` PostHog experiment for a given
* variant. Returns an empty array for `control` or any unknown variant — the
* caller is responsible for de-duping against features the user already passed.
*
* Kept as a pure, named export so the bundle composition is testable in
* isolation from `main()` arg parsing. This is the experiment surface only —
* unrelated to `--fast`, which is its own user-facing flag and stays as-is.
*/
export function expandFastProvisionVariant(variant: string): readonly string[] {
if (variant === "test") {
return [
"images",
"docker",
"sandbox",
];
}
return [];
}

/** Test-only: reset module state between tests. */
export function _resetFeatureFlagsForTest(): void {
_flags = null;
Expand Down
Loading