Skip to content

Commit 4fb9e5d

Browse files
maria-rckseyeveil
andauthored
fix(server): dev database copies drop links to other environments (#27313)
Co-authored-by: Nik <[email protected]>
1 parent 77f08e6 commit 4fb9e5d

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ The most common defect in this repo is a change that works on the path you teste
9191
An empty database is a bad test. Seed your worktree's `.t3` with a copy of real data instead of pointing at live state:
9292

9393
- The first `vp run dev` in a worktree does this for you when its database is missing and the source is at most 500 MiB. Larger sources warn and dev starts with an empty database. `--no-seed` or `T3CODE_DEV_SEED=0` skips seeding. Manual migration still accepts larger sources and may use substantial disk space before pruning.
94-
- Run `vp run migrate-dev-db` with your dev server stopped to refresh. It rebuilds `<worktree>/.t3/userdata/statev2.sqlite` from a read-only snapshot of `~/.t3/userdata/statev2.sqlite`, the developer's real data. It keeps recent projects and their stopped threads, and drops scheduled tasks, pending work, and auth sessions, so your dev server never runs the developer's agents. Raise `--projects` and `--threads-per-project` for more data.
94+
- Run `vp run migrate-dev-db` with your dev server stopped to refresh. It rebuilds `<worktree>/.t3/userdata/statev2.sqlite` from a read-only snapshot of `~/.t3/userdata/statev2.sqlite`, the developer's real data. It keeps recent projects and their stopped threads, and drops scheduled tasks, pending work, auth sessions, and links to other environments, so your dev server never runs the developer's agents or reaches their other machines. Raise `--projects` and `--threads-per-project` for more data.
9595
- Refresh `statev2.sqlite`, not `state.sqlite`. The server copies the V1 `state.sqlite` only when `statev2.sqlite` is missing.
9696
- Bring `secrets` and `settings.json` only if the flow under test needs them.
9797
- Copy in, never symlink. Data flows one way: into your sandbox, never back out.

‎apps/server/scripts/migrate-dev-db.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ const createFixtureSource = Effect.fn("createMigrateDevDbFixtureSource")(functio
9595
VALUES ('delivery-1', 'task-1', 'key-1', 1900000000000, '{}', '{}', '[]')`;
9696
yield* sql`INSERT INTO auth_sessions (session_id, subject, scopes, method, issued_at, expires_at)
9797
VALUES ('session-1', 'user', '[]', 'pairing', '2026-08-01', '2027-08-01')`;
98+
yield* sql`INSERT INTO peer_environment_links
99+
(environment_id, secret_name, label, urls_json, access, linked_at, expires_at)
100+
VALUES ('environment-box', 'peer-link-box', 'Box', '["https://box.example"]', 'auto',
101+
'2026-08-01', '2027-08-01')`;
98102
}),
99103
);
100104
return databasePath;
@@ -130,13 +134,15 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
130134
tasks: number;
131135
webhooks: number;
132136
transfers: number;
137+
links: number;
133138
}>`
134139
SELECT
135140
(SELECT COUNT(*) FROM auth_sessions) AS auth,
136141
(SELECT COUNT(*) FROM scheduled_tasks) AS tasks,
137142
(SELECT COUNT(*) FROM scheduled_task_webhook_replay_keys) +
138143
(SELECT COUNT(*) FROM scheduled_task_webhook_pending) AS webhooks,
139-
(SELECT COUNT(*) FROM orchestration_v2_projection_context_transfers) AS transfers`;
144+
(SELECT COUNT(*) FROM orchestration_v2_projection_context_transfers) AS transfers,
145+
(SELECT COUNT(*) FROM peer_environment_links) AS links`;
140146
return { threads, events, sessions, leftovers };
141147
}),
142148
);
@@ -152,7 +158,13 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
152158
kept.sessions.map((row) => row.provider_session_id),
153159
["session-shared"],
154160
);
155-
assert.deepStrictEqual(kept.leftovers, { auth: 0, tasks: 0, webhooks: 0, transfers: 0 });
161+
assert.deepStrictEqual(kept.leftovers, {
162+
auth: 0,
163+
tasks: 0,
164+
webhooks: 0,
165+
transfers: 0,
166+
links: 0,
167+
});
156168
}),
157169
);
158170

‎apps/server/scripts/migrate-dev-db.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ const CLEARED_TABLES: ReadonlyArray<string> = [
211211
"provider_session_runtime",
212212
"auth_sessions",
213213
"auth_pairing_links",
214+
"peer_environment_links",
214215
];
215216

216217
const PROVIDER_SESSIONS_TABLE = "orchestration_v2_projection_provider_sessions";

0 commit comments

Comments
 (0)