Skip to content

Commit 96d49b8

Browse files
Merge remote-tracking branch 'origin/staging' into feat/table-block-v2
# Conflicts: # scripts/check-api-validation-contracts.ts
2 parents 808bc0d + edef789 commit 96d49b8

262 files changed

Lines changed: 44891 additions & 4619 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI Cache Cleanup
2+
3+
# DRAINING LEGACY DISKS ONLY. test-build.yml no longer mounts a Next.js build
4+
# cache — the Turbopack persistent cache measured 3.2x SLOWER than no cache, so it
5+
# is off. But every PR open while the per-branch key was live left a 5-12 GB volume
6+
# behind, and nothing else reclaims them. This keeps deleting them as those PRs
7+
# close.
8+
#
9+
# Delete this workflow once the backlog is drained (no PR predating the cache
10+
# removal is still open). It is a no-op for new PRs, which never create a disk.
11+
12+
on:
13+
pull_request:
14+
types: [closed]
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
delete-nextjs-cache:
21+
name: Delete Next.js build cache disk
22+
# Sticky disks only exist on Blacksmith; the GitHub break-glass path uses
23+
# actions/cache, which expires on its own.
24+
if: vars.CI_PROVIDER == '' || vars.CI_PROVIDER == 'blacksmith'
25+
runs-on: blacksmith-2vcpu-ubuntu-2404
26+
timeout-minutes: 5
27+
28+
steps:
29+
# A hard-coded legacy drain key. It no longer mirrors anything — the
30+
# Mount Next.js build cache step it used to match was removed with the
31+
# cache. Do not retarget or delete it while PRs from before that removal
32+
# are still open, or their 5-12 GB disks are never reclaimed.
33+
# Non-blocking: PRs skipped by ci.yml's paths-ignore never made a disk,
34+
# and neither does any PR opened after the removal.
35+
- name: Delete sticky disk
36+
uses: useblacksmith/stickydisk-delete@b41313d28b8647d72114c9ba3c96bb04061562b6 # v1
37+
continue-on-error: true
38+
with:
39+
delete-key: ${{ github.repository }}-nextjs-cache-pull_request${{ github.event.pull_request.head.repo.fork && '-fork' || '' }}-${{ github.head_ref }}

.github/workflows/test-build.yml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ jobs:
177177
- name: Install ripgrep
178178
run: command -v rg || (sudo apt-get update && sudo apt-get install -y ripgrep)
179179

180-
- name: Run tests with coverage
180+
# Named for what it does: `bun run test` is `vitest run`, with no
181+
# `--coverage`. See the Codecov note below.
182+
- name: Run tests
181183
env:
182184
NODE_OPTIONS: '--no-warnings --max-old-space-size=8192'
183185
NEXT_PUBLIC_APP_URL: 'https://www.sim.ai'
@@ -199,6 +201,14 @@ jobs:
199201
fi
200202
echo "✅ Schema and migrations are in sync"
201203
204+
# DEAD PATH: nothing generates `apps/sim/coverage`. The test step runs
205+
# `vitest run` without `--coverage`, and vitest.config.ts declares no
206+
# coverage provider, so this uploads nothing and still reports success in
207+
# ~1s (`fail_ci_if_error: false` hides it). `@vitest/coverage-v8` IS
208+
# installed, so wiring it up is possible — but coverage instrumentation
209+
# costs test time and nothing gates on the result today. Left in place
210+
# pending a decision to either enable coverage or drop this step; do not
211+
# read its green tick as "coverage was published".
202212
- name: Upload coverage to Codecov
203213
uses: codecov/codecov-action@0fb7174895f61a3b6b78fc075e0cd60383518dac # v5
204214
with:
@@ -263,17 +273,12 @@ jobs:
263273
key: ${{ github.repository }}-turbo-cache-build-${{ github.event_name }}${{ github.event.pull_request.head.repo.fork && '-fork' || '' }}
264274
path: ./.turbo
265275

266-
# Turbopack's persistent build cache (NEXT_TURBOPACK_BUILD_CACHE below)
267-
# writes ~5 GB into .next/cache — a sticky disk mounts it in ~1s where an
268-
# actions/cache round-trip would eat the warm-build win. Same event/fork
269-
# namespacing as the other mounts; the GitHub fallback inside cache-mount
270-
# still uses actions/cache with a run_id-suffixed key.
271-
- name: Mount Next.js build cache
272-
uses: ./.github/actions/cache-mount
273-
with:
274-
provider: ${{ vars.CI_PROVIDER }}
275-
key: ${{ github.repository }}-nextjs-cache-${{ github.event_name }}${{ github.event.pull_request.head.repo.fork && '-fork' || '' }}
276-
path: ./apps/sim/.next/cache
276+
# No `.next/cache` mount: the Turbopack persistent build cache is off. A
277+
# controlled A/B on one branch (PR #6078) with a byte-identical module graph
278+
# measured compile at 113s with the cache off, 162s cold with it on, and
279+
# 360s warm — the cache made the same build 3.2x slower, and it grew
280+
# 5.1 GB -> 12 GB across two runs of an unchanged tree, so a disk degrades
281+
# the more it is used. Mounting a disk nothing reads would only cost storage.
277282

278283
# Running out of RAM kills the whole VM and surfaces only as "the runner
279284
# has received a shutdown signal" — no mention of memory, ~12 min in. Warn
@@ -304,7 +309,4 @@ jobs:
304309
AWS_REGION: 'us-west-2'
305310
ENCRYPTION_KEY: '7cf672e460e430c1fba707575c2b0e2ad5a99dddf9b7b7e3b5646e630861db1c' # dummy key for CI only
306311
TURBO_CACHE_DIR: .turbo
307-
# Opt into Turbopack's persistent build cache (beta) for this CI
308-
# check build only — measured 105s cold vs 22s warm locally.
309-
NEXT_TURBOPACK_BUILD_CACHE: '1'
310312
run: bunx turbo run build --filter=sim

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,14 @@ i18n.cache
102102
# Python (apps/pii tests/tooling)
103103
__pycache__/
104104
.pytest_cache/
105+
106+
# Local file-upload spill directory. `UPLOAD_DIR_SERVER` is
107+
# `join(process.cwd(), 'uploads')`, so it follows the cwd rather than a fixed
108+
# root: under `turbo run test` the cwd is apps/sim and `apps/sim/.gitignore`'s
109+
# `/uploads` catches it, but running vitest from the repo root drops ~40
110+
# `uploads/execution/**/large-value-*.json` files here instead.
111+
#
112+
# Anchored deliberately. An unanchored `uploads/` would also match
113+
# `apps/sim/lib/uploads/` — 61 files of tracked source — and silently ignore
114+
# anything added there later.
115+
/uploads

apps/desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"start": "electron .",
1919
"package:dir": "bun run build && electron-builder --mac dir --publish never",
2020
"package:mac": "bun run build && electron-builder --mac --publish never",
21-
"package:share": "bun run build && electron-builder --mac --publish never -c.mac.timestamp=none",
21+
"package:share": "bun run scripts/package-share.ts",
2222
"install:local": "bun run scripts/install-local.ts",
2323
"type-check": "tsc --noEmit",
2424
"lint": "biome check --write --unsafe .",

apps/desktop/scripts/channels.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Build-time channel identity, derived from the origin a build is baked to.
3+
*
4+
* Must stay in sync with APP_NAME_FOR_CHANNEL / channelForOrigin in
5+
* src/main/config.ts. That pair is the RUNTIME source of truth — the app calls
6+
* app.setName() from its baked origin at startup, which decides the userData
7+
* directory and single-instance lock — and this is what the packager stamps
8+
* into the bundle. When the two disagree, the bundle on disk and the running
9+
* app disagree about which app they are: a dev-pointed build packaged as
10+
* "Sim.app" with the production bundle id installs over a real production
11+
* install while naming itself "Sim Dev" at runtime.
12+
*/
13+
14+
/** Canonical no-redirect origins per environment. */
15+
export const PROD_ORIGIN = 'https://www.sim.ai'
16+
export const STAGING_ORIGIN = 'https://www.staging.sim.ai'
17+
export const DEV_ORIGIN = 'https://www.dev.sim.ai'
18+
export const LOCAL_ORIGIN = 'http://localhost:3000'
19+
20+
export interface ChannelIdentity {
21+
/** Display + bundle name; also the userData directory name. */
22+
name: string
23+
appId: string
24+
/** Baked default origin + persisted settings origin. */
25+
origin: string
26+
/**
27+
* Artifact filename stem, and the per-channel scratch directory name.
28+
* Space-free for the same reason electron-builder.yml's artifactName is:
29+
* GitHub rewrites asset names containing spaces, which desyncs the
30+
* electron-updater manifest from the uploaded files.
31+
*/
32+
slug: string
33+
}
34+
35+
export const PROD: ChannelIdentity = {
36+
name: 'Sim',
37+
appId: 'ai.sim.desktop',
38+
origin: PROD_ORIGIN,
39+
slug: 'sim',
40+
}
41+
export const STAGING: ChannelIdentity = {
42+
name: 'Sim Staging',
43+
appId: 'ai.sim.desktop.staging',
44+
origin: STAGING_ORIGIN,
45+
slug: 'sim-staging',
46+
}
47+
export const DEV: ChannelIdentity = {
48+
name: 'Sim Dev',
49+
appId: 'ai.sim.desktop.dev',
50+
origin: DEV_ORIGIN,
51+
slug: 'sim-dev',
52+
}
53+
export const LOCAL: ChannelIdentity = {
54+
name: 'Sim Local',
55+
appId: 'ai.sim.desktop.local',
56+
origin: LOCAL_ORIGIN,
57+
slug: 'sim-local',
58+
}
59+
60+
/** Every channel, in the order a full run builds them. */
61+
export const ALL_CHANNELS: readonly ChannelIdentity[] = [PROD, STAGING, DEV, LOCAL]
62+
63+
/**
64+
* Resolves the identity a build baked to `origin` must carry. Mirrors
65+
* channelForOrigin in src/main/config.ts, including its fall-through to
66+
* production for unrecognized hosts (self-hosted origins are production
67+
* builds pointed elsewhere). An empty origin means "unset", which the app
68+
* resolves to DEFAULT_ORIGIN — production.
69+
*/
70+
export function identityForOrigin(origin: string): ChannelIdentity {
71+
if (!origin) return PROD
72+
let host: string
73+
try {
74+
host = new URL(origin).hostname.toLowerCase()
75+
} catch {
76+
return PROD
77+
}
78+
if (host === 'localhost' || host === '127.0.0.1') return LOCAL
79+
if (host === 'dev.sim.ai' || host.endsWith('.dev.sim.ai')) return DEV
80+
if (host === 'staging.sim.ai' || host.endsWith('.staging.sim.ai')) return STAGING
81+
return PROD
82+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/**
2+
* Share build: packages distributable .dmg/.zip artifacts from the current
3+
* checkout, signed with whatever identity is on the machine (no notarization,
4+
* no trusted timestamps) — the "send someone a build to try" loop.
5+
*
6+
* bun run package:share # production only
7+
* bun run package:share --all # all four channels
8+
* bun run package:share --staging --dev # just these two
9+
* bun run package:share --dir # skip dmg/zip, package the .app only (fast)
10+
* SIM_DESKTOP_DEFAULT_ORIGIN=https://sim.acme.example bun run package:share
11+
*
12+
* Each channel lands in release/<slug>/ with artifacts named for it — sim,
13+
* sim-staging, sim-dev, sim-local. electron-builder.yml's artifactName is a
14+
* single literal ("Sim-${version}-${arch}"), so without the override every
15+
* channel writes the same filename and the last build silently wins. Only this
16+
* path overrides it: the release workflow publishes one channel per GitHub
17+
* release, where the flat name is what electron-updater expects.
18+
*
19+
* The baked origin decides the bundle identity, exactly as it decides the
20+
* runtime one. This used to shell straight into electron-builder, which took
21+
* productName/appId from electron-builder.yml — always the production pair — so
22+
* a dev-pointed share packaged as "Sim.app" with the production bundle id while
23+
* naming itself "Sim Dev" at runtime.
24+
*
25+
* Channels build ONE AT A TIME on purpose. scripts/build.ts writes the bundle
26+
* to dist/ and the app icon to build/generated-icon.icns, both fixed paths, so
27+
* concurrent channels would overwrite each other's bundle mid-package and ship
28+
* a dmg whose baked origin belongs to a different environment — invisible until
29+
* someone signs in. Giving each channel its own bundle directory is what would
30+
* make concurrency safe, and the flag that redirects the app entry point
31+
* (-c.extraMetadata.main) rewrites this package.json IN THE SOURCE TREE,
32+
* stripping scripts and devDependencies. If parallelism is worth it later, the
33+
* way to get it is a per-channel project directory (electron-builder --project)
34+
* — not extraMetadata.
35+
*/
36+
import { spawnSync } from 'node:child_process'
37+
import { rmSync } from 'node:fs'
38+
import { ALL_CHANNELS, type ChannelIdentity, identityForOrigin } from './channels'
39+
40+
const FLAG_TO_CHANNEL: Record<string, ChannelIdentity> = Object.fromEntries(
41+
ALL_CHANNELS.map((channel) => [
42+
`--${channel.slug.replace(/^sim-/, '').replace(/^sim$/, 'prod')}`,
43+
channel,
44+
])
45+
)
46+
47+
const args = process.argv.slice(2)
48+
const dirOnly = args.includes('--dir')
49+
const bakedOriginOverride = process.env.SIM_DESKTOP_DEFAULT_ORIGIN ?? ''
50+
51+
function selectedChannels(): ChannelIdentity[] {
52+
if (args.includes('--all')) return [...ALL_CHANNELS]
53+
const picked = args.filter((arg) => arg in FLAG_TO_CHANNEL).map((arg) => FLAG_TO_CHANNEL[arg])
54+
if (picked.length > 0) return picked
55+
// No channel flags: honour an explicit origin (self-hosted shares resolve to
56+
// the production identity), otherwise plain production.
57+
return [identityForOrigin(bakedOriginOverride)]
58+
}
59+
60+
const channels = selectedChannels()
61+
// An explicit origin only makes sense for a single-channel run; with several
62+
// channels each one supplies its own.
63+
const originFor = (channel: ChannelIdentity): string =>
64+
channels.length === 1 && bakedOriginOverride ? bakedOriginOverride : channel.origin
65+
66+
function run(command: string, commandArgs: string[], env?: Record<string, string>): void {
67+
const result = spawnSync(command, commandArgs, {
68+
stdio: 'inherit',
69+
env: env ? { ...process.env, ...env } : process.env,
70+
})
71+
if (result.status !== 0) {
72+
console.error(`\n✖ ${command} ${commandArgs.join(' ')} failed`)
73+
process.exit(result.status ?? 1)
74+
}
75+
}
76+
77+
function buildChannel(channel: ChannelIdentity): void {
78+
const origin = originFor(channel)
79+
console.log(`\n• ${channel.slug}: ${channel.name} (${channel.appId}) → ${origin}`)
80+
81+
// electron-builder only writes the output dir for the CURRENT target/arch, so
82+
// an app left by an earlier run with different settings would survive
83+
// alongside the new one.
84+
for (const dir of ['mac-universal', 'mac-arm64', 'mac']) {
85+
rmSync(`release/${channel.slug}/${dir}`, { recursive: true, force: true })
86+
}
87+
// electron-builder's `files: dist/**` packages whatever is in dist/, not just
88+
// what this build wrote. Anything left there by an earlier run — another
89+
// channel's bundle, scratch from an experiment — rides along inside the dmg,
90+
// so a production artifact can end up carrying a dev-pointed bundle. Dead
91+
// weight rather than a live risk (the app boots package.json's `main`), but
92+
// not something to hand to anyone. build.ts rewrites the directory on the
93+
// next line.
94+
rmSync('dist', { recursive: true, force: true })
95+
96+
run('bun', ['run', 'scripts/build.ts'], { SIM_DESKTOP_DEFAULT_ORIGIN: origin })
97+
run('bunx', [
98+
'electron-builder',
99+
'--mac',
100+
...(dirOnly ? ['dir'] : []),
101+
'--publish',
102+
'never',
103+
// Trusted timestamps make codesign do a network round trip to Apple per
104+
// file (hundreds inside the Electron framework). Distribution builds need
105+
// them; a share build does not, and it turns signing into a long stall.
106+
'-c.mac.timestamp=none',
107+
`-c.productName=${channel.name}`,
108+
`-c.appId=${channel.appId}`,
109+
`-c.directories.output=release/${channel.slug}`,
110+
// The ${...} placeholders are electron-builder's own templating, expanded
111+
// by it at packaging time — escaped here so JS leaves them alone.
112+
`-c.artifactName=${channel.slug}-\${version}-\${arch}.\${ext}`,
113+
])
114+
console.log(`✔ ${channel.slug}: release/${channel.slug}/`)
115+
}
116+
117+
// Shared node_modules state, and the one step every channel has in common.
118+
run('bun', ['run', 'scripts/ensure-pty-prebuilds.ts'])
119+
console.log(
120+
`• Building ${channels.length} channel(s)${dirOnly ? ' (dir only)' : ''}: ${channels.map((c) => c.slug).join(', ')}`
121+
)
122+
for (const channel of channels) {
123+
buildChannel(channel)
124+
}

0 commit comments

Comments
 (0)