Skip to content

Commit 5673c33

Browse files
mahanticodexFizzFizz
authored
feat(desktop): add protected-build Bestie experiment (block#6902)
## Summary Introduces a protected-build boundary for the default-off Bestie experiment without adding any Bestie product surface. - Official OSS builds select an empty protected-feature module and emit no Bestie/Chief metadata or implementation content. - Protected internal builds select a separate module graph containing the Bestie experiment definition. - Within an internal build, Bestie remains disabled until the user opts in under Settings → Experiments. - The production build runs an artifact matrix and fails if OSS output contains protected content or internal output lacks the Bestie manifest. ## Build contract | Build variant | User opt-in | Result | | --- | --- | --- | | Official OSS | Any/forged | Bestie absent from the compiled artifact | | Protected internal | Off | Bestie available but disabled | | Protected internal | On | Bestie enabled | The companion protected-release change is squareup/buzz-releases#91. It sets `VITE_BUZZ_BESTIE=1`, requires that exact value, forwards it into the signed macOS build, and asserts the contract in release validation. ## Why this is separate This gives later Bestie PRs one build-selected import seam. Protected implementations must be reachable only from the internal module so they never enter the official OSS module graph. ## Non-goals - No Bestie persona or provisioning - No sidebar, app-chrome, or message-toolbar UI - No entitlement or secrecy claim: the source is public; this boundary controls official Block artifacts ## Verification - Exact commit `523cf49ced03cba9be43836a54d6aa5d6923cc82` - Full `just ci`: 5,673 Desktop tests, 2,773 Tauri tests, 1,860 mobile tests, Rust/Tauri/web/mobile static checks and builds - OSS production artifact: scanner confirms no `Bestie`, `Chief of Staff`, or `builtin:bestie` content - Internal production artifact: scanner confirms the protected Bestie manifest is emitted - Both build orders verified; `dist` retains the requested variant for Vite/Tauri packaging --------- Signed-off-by: Arjun Mahanti <[email protected]> Signed-off-by: Fizz <[email protected]> Signed-off-by: Fizz <dae5f6af70b8695a8b83c8deae555f63be41630ec2b8cd493e41a439c9527dd8@buzz.block.builderlab.xyz> Co-authored-by: Codex <[email protected]> Co-authored-by: Fizz <[email protected]> Co-authored-by: Fizz <dae5f6af70b8695a8b83c8deae555f63be41630ec2b8cd493e41a439c9527dd8@buzz.block.builderlab.xyz>
1 parent 2f3dd85 commit 5673c33

16 files changed

Lines changed: 569 additions & 56 deletions

‎.env.example‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ RUST_LOG=buzz_relay=debug,buzz_datastore=info,buzz_db=debug,buzz_auth=debug,buzz
274274
# app launch while keeping the current identity and relay data.
275275
# VITE_BUZZ_FORCE_FRESH_ONBOARDING=true
276276

277+
# Protected internal builds only: selects the module graph that contains the
278+
# default-off Bestie experiment. Official OSS builds must leave this unset.
279+
# VITE_BUZZ_BESTIE=1
280+
277281
# ── Subscription & filtering ─────────────────────────────────────────────────
278282
# Subscribe mode: "mentions" (default), "all", or "config" (rule-based).
279283
# BUZZ_ACP_SUBSCRIBE=mentions

‎.github/workflows/ci.yml‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ jobs:
304304
name: Desktop
305305
runs-on: ubuntu-latest
306306
timeout-minutes: 5
307-
needs: [changes, desktop-core, desktop-smoke-e2e]
307+
needs: [changes, desktop-core, desktop-smoke-e2e, desktop-windows-build]
308308
if: always() && (github.event_name == 'push' || needs.changes.outputs.desktop == 'true' || needs.changes.outputs.desktop-rust == 'true' || needs.changes.outputs.rust == 'true')
309309
permissions:
310310
contents: read
@@ -319,6 +319,10 @@ jobs:
319319
echo "Desktop Smoke E2E shards finished with: ${{ needs.desktop-smoke-e2e.result }}"
320320
exit 1
321321
fi
322+
if [ "${{ needs.desktop-windows-build.result }}" != "success" ]; then
323+
echo "Desktop Windows Build finished with: ${{ needs.desktop-windows-build.result }}"
324+
exit 1
325+
fi
322326
echo "Desktop jobs passed"
323327
324328
desktop-e2e-relay:
@@ -1133,6 +1137,36 @@ jobs:
11331137
-p git-credential-nostr \
11341138
-p git-sign-nostr
11351139
1140+
desktop-windows-build:
1141+
name: Desktop Windows Build
1142+
runs-on: windows-latest
1143+
timeout-minutes: 20
1144+
needs: [changes]
1145+
if: github.event_name == 'push' || needs.changes.outputs.desktop == 'true' || needs.changes.outputs.desktop-rust == 'true' || needs.changes.outputs.rust == 'true'
1146+
permissions:
1147+
contents: read
1148+
steps:
1149+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
1150+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
1151+
with:
1152+
node-version: 24.14.1
1153+
package-manager-cache: false
1154+
- uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0
1155+
with:
1156+
version: 11.4.0
1157+
- name: Install desktop dependencies
1158+
shell: bash
1159+
run: pnpm install --frozen-lockfile
1160+
- name: Build both protected-feature selections
1161+
shell: pwsh
1162+
run: |
1163+
Remove-Item Env:VITE_BUZZ_BESTIE -ErrorAction SilentlyContinue
1164+
pnpm -C desktop build
1165+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
1166+
$env:VITE_BUZZ_BESTIE = "1"
1167+
pnpm -C desktop build
1168+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
1169+
11361170
windows-rust:
11371171
name: Windows Rust (x86_64-pc-windows-msvc)
11381172
runs-on: windows-latest

‎desktop/package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8-
"build": "tsc && vite build",
8+
"build": "tsc && node ./scripts/build-protected-feature-artifacts.mjs",
99
"build:e2e": "tsc && vite build --mode e2e",
1010
"typecheck": "tsc --noEmit",
1111
"check:file-sizes": "node ./scripts/check-file-sizes.mjs",
@@ -16,13 +16,13 @@
1616
"format": "biome format --write .",
1717
"test": "node --import ./test-loader.mjs --experimental-strip-types --test \"src/**/*.test.mjs\"",
1818
"preview": "vite preview",
19-
"tauri": "tauri",
19+
"tauri": "node ./scripts/tauri-command.mjs",
2020
"test:e2e": "pnpm build:e2e && playwright test",
2121
"test:e2e:smoke": "pnpm build:e2e && playwright test --project=smoke",
2222
"test:e2e:integration": "pnpm build:e2e && playwright test --project=integration",
2323
"test:e2e:release-smoke": "pnpm build:e2e && playwright test --config=playwright.release-smoke.config.ts",
2424
"test:e2e:report": "playwright show-report",
25-
"tauri:build": "tauri build"
25+
"tauri:build": "node ./scripts/tauri-command.mjs build"
2626
},
2727
"dependencies": {
2828
"@dnd-kit/core": "^6.3.1",
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import { spawnSync } from "node:child_process";
2+
import {
3+
mkdtempSync,
4+
readFileSync,
5+
readdirSync,
6+
rmSync,
7+
statSync,
8+
} from "node:fs";
9+
import { tmpdir } from "node:os";
10+
import path from "node:path";
11+
import { fileURLToPath } from "node:url";
12+
import { loadEnv } from "vite";
13+
14+
const desktopRoot = path.resolve(
15+
path.dirname(fileURLToPath(import.meta.url)),
16+
"..",
17+
);
18+
const vitePackageJsonPath = fileURLToPath(
19+
import.meta.resolve("vite/package.json"),
20+
);
21+
const vitePackage = JSON.parse(readFileSync(vitePackageJsonPath, "utf8"));
22+
const viteEntrypoint = path.resolve(
23+
path.dirname(vitePackageJsonPath),
24+
vitePackage.bin.vite,
25+
);
26+
27+
function buildVariant({ internal, output }) {
28+
const env = {
29+
...process.env,
30+
// Pin both children explicitly. Deleting the OSS value lets Vite reload
31+
// `=1` from .env.local or a mode-specific env file.
32+
VITE_BUZZ_BESTIE: internal ? "1" : "0",
33+
};
34+
35+
const result = spawnSync(
36+
process.execPath,
37+
[viteEntrypoint, "build", "--outDir", output, "--emptyOutDir"],
38+
{
39+
cwd: desktopRoot,
40+
env,
41+
stdio: "inherit",
42+
},
43+
);
44+
if (result.error) throw result.error;
45+
if (result.status !== 0) {
46+
throw new Error(
47+
`${internal ? "internal" : "OSS"} desktop build failed with status ${result.status}`,
48+
);
49+
}
50+
}
51+
52+
function emittedText(root) {
53+
const chunks = [];
54+
const visit = (candidate) => {
55+
const stat = statSync(candidate);
56+
if (stat.isDirectory()) {
57+
for (const child of readdirSync(candidate)) {
58+
visit(path.join(candidate, child));
59+
}
60+
return;
61+
}
62+
if (/\.(?:css|html|js|json)$/u.test(candidate)) {
63+
chunks.push(readFileSync(candidate, "utf8"));
64+
}
65+
};
66+
visit(root);
67+
return chunks.join("\n");
68+
}
69+
70+
export function assertArtifactContract({ ossOutput, internalOutput }) {
71+
const ossText = emittedText(ossOutput);
72+
const internalText = emittedText(internalOutput);
73+
const protectedContent = /\bbestie\b|chief of staff|builtin:bestie/iu;
74+
const internalManifestMarker =
75+
"Try a personal agent that is always close at hand";
76+
77+
if (protectedContent.test(ossText)) {
78+
throw new Error(
79+
"Official OSS desktop artifact contains protected Bestie/Chief content",
80+
);
81+
}
82+
if (!internalText.includes(internalManifestMarker)) {
83+
throw new Error(
84+
"Protected internal desktop artifact is missing the Bestie manifest",
85+
);
86+
}
87+
}
88+
89+
/** Resolve the requested output with the same precedence used by Vite config. */
90+
export function selectInternalVariant({ processEnv, modeEnv }) {
91+
return (processEnv.VITE_BUZZ_BESTIE ?? modeEnv.VITE_BUZZ_BESTIE) === "1";
92+
}
93+
94+
/** Build and inspect both graphs, leaving the requested variant in dist. */
95+
export function buildArtifactMatrix({
96+
selectedInternalVariant,
97+
selectedOutput,
98+
alternateOutput,
99+
build = buildVariant,
100+
}) {
101+
// Build the unselected variant outside dist first, then leave the requested
102+
// variant in dist for Vite/Tauri's ordinary packaging contract.
103+
build({
104+
internal: !selectedInternalVariant,
105+
output: alternateOutput,
106+
});
107+
build({
108+
internal: selectedInternalVariant,
109+
output: selectedOutput,
110+
});
111+
112+
assertArtifactContract({
113+
ossOutput: selectedInternalVariant ? alternateOutput : selectedOutput,
114+
internalOutput: selectedInternalVariant ? selectedOutput : alternateOutput,
115+
});
116+
}
117+
118+
function main() {
119+
const selectedInternalVariant = selectInternalVariant({
120+
processEnv: process.env,
121+
modeEnv: loadEnv("production", desktopRoot, ""),
122+
});
123+
const scratchRoot = mkdtempSync(
124+
path.join(tmpdir(), "buzz-protected-feature-artifacts-"),
125+
);
126+
const selectedOutput = process.env.BUZZ_PROTECTED_BUILD_OUTPUT
127+
? path.resolve(process.env.BUZZ_PROTECTED_BUILD_OUTPUT)
128+
: path.join(desktopRoot, "dist");
129+
const alternateOutput = path.join(scratchRoot, "alternate");
130+
131+
try {
132+
buildArtifactMatrix({
133+
selectedInternalVariant,
134+
selectedOutput,
135+
alternateOutput,
136+
});
137+
} finally {
138+
rmSync(scratchRoot, { recursive: true, force: true });
139+
}
140+
141+
console.log(
142+
`Protected feature artifact matrix passed; dist contains the ${selectedInternalVariant ? "internal" : "OSS"} variant.`,
143+
);
144+
}
145+
146+
if (
147+
process.argv[1] &&
148+
path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
149+
) {
150+
main();
151+
}

‎desktop/scripts/tauri-command.mjs‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { spawnSync } from "node:child_process";
2+
import { readFileSync } from "node:fs";
3+
import { mkdtempSync, rmSync } from "node:fs";
4+
import { tmpdir } from "node:os";
5+
import path from "node:path";
6+
import { fileURLToPath } from "node:url";
7+
8+
const desktopRoot = path.resolve(
9+
path.dirname(fileURLToPath(import.meta.url)),
10+
"..",
11+
);
12+
const tauriPackageJsonPath = fileURLToPath(
13+
import.meta.resolve("@tauri-apps/cli/package.json"),
14+
);
15+
const tauriPackage = JSON.parse(readFileSync(tauriPackageJsonPath, "utf8"));
16+
const defaultTauriEntrypoint = path.resolve(
17+
path.dirname(tauriPackageJsonPath),
18+
tauriPackage.bin.tauri,
19+
);
20+
21+
function runTauri(args, options = {}) {
22+
const entrypoint =
23+
process.env.BUZZ_TAURI_CLI_ENTRYPOINT ?? defaultTauriEntrypoint;
24+
const result = spawnSync(process.execPath, [entrypoint, ...args], {
25+
cwd: desktopRoot,
26+
env: { ...process.env, ...options.env },
27+
stdio: "inherit",
28+
});
29+
if (result.error) throw result.error;
30+
return result.status ?? 1;
31+
}
32+
33+
export function runTauriCommand(args) {
34+
if (args[0] !== "build") return runTauri(args);
35+
36+
// Tauri runs beforeBuildCommand and then consumes frontendDist. Give the
37+
// entire invocation a private directory so concurrent OSS/internal packages
38+
// cannot replace one another's assets between those two operations.
39+
const invocationRoot = mkdtempSync(
40+
path.join(tmpdir(), "buzz-tauri-package-assets-"),
41+
);
42+
const frontendDist = path.join(invocationRoot, "dist");
43+
const outputOverride = JSON.stringify({ build: { frontendDist } });
44+
45+
try {
46+
const delimiterIndex = args.indexOf("--");
47+
const configIndex = delimiterIndex === -1 ? args.length : delimiterIndex;
48+
const tauriArgs = [...args];
49+
tauriArgs.splice(configIndex, 0, "--config", outputOverride);
50+
return runTauri(tauriArgs, {
51+
env: { BUZZ_PROTECTED_BUILD_OUTPUT: frontendDist },
52+
});
53+
} finally {
54+
rmSync(invocationRoot, { recursive: true, force: true });
55+
}
56+
}
57+
58+
if (
59+
process.argv[1] &&
60+
path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
61+
) {
62+
process.exitCode = runTauriCommand(process.argv.slice(2));
63+
}

‎desktop/src/features/settings/ui/SettingsView.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {
77
canManageCommunityMembers,
88
shouldWarnMissingMembershipSnapshot,
99
} from "@/shared/api/relayMembers";
10-
import { getFeature } from "@/shared/features/manifest";
1110
import {
11+
getFeature,
1212
resolveEnabled,
1313
useFeatureSnapshot,
14-
} from "@/shared/features/useFeatureEnabled";
14+
} from "@/shared/features";
1515
import { topChromeBackdrop } from "@/shared/layout/chromeLayout";
1616
import { cn } from "@/shared/lib/cn";
1717
import {
@@ -137,7 +137,10 @@ export function SettingsView({
137137
// stable and renders unconditionally (fail-open).
138138
if (s.featureGate) {
139139
const feature = getFeature(s.featureGate);
140-
if (feature && !resolveEnabled(s.featureGate, featureState)) {
140+
if (
141+
feature &&
142+
!resolveEnabled(s.featureGate, featureState, feature.defaultEnabled)
143+
) {
141144
return false;
142145
}
143146
}

0 commit comments

Comments
 (0)