mirror of
https://github.com/simstudioai/sim.git
synced 2026-11-20 12:08:01 +08:00
* feat(projects): add project identity and lifecycle foundation * feat(projects): create projects with their initial environment * docs(projects): record project files follow-up * docs(projects): explain project and workspace creation flows * fix(projects): stage activation after compatible writers deploy * feat(projects): enforce membership after the staged backfill * fix(projects): retry writes after concurrent membership changes * fix(projects): align integration fixtures with membership constraints * refactor(projects): prepare compatible writers for the SQL backfill * refactor(projects): backfill through bounded SQL migration batches * fix(projects): clean up automatically created fixture Projects * fix(projects): backfill only families missing membership * fix(projects): bound the trigger installation lock window * fix(workflows): guard restore against concurrent workspace archive * fix(projects): keep workflow lifecycle guards at workspace scope * fix(workflows): guard restore against concurrent workspace archive * fix(projects): close lifecycle races and surface rollout conflicts * fix(workflows): return not found when import loses archive race * fix(projects): tighten rollout checks and deduplicate lifecycle validation * test(projects): detect missing lifecycle validation calls * test(projects): verify concurrent lifecycle lock contention * feat: establish durable file ownership and rollout compatibility Add canonical entity ownership while preserving legacy workspace writers. Make storage accounting, lifecycle cleanup, search, document artifacts, and realtime transport tolerate project-owned data before feature activation. Keep Project file user/API/tool entry points in the stacked feature change. * test: align file ownership fixtures and validation reports * refactor: persist file owners with native foreign keys * fix(db): parenthesize the file owner search index expression * test(projects): update new workspace fixtures for enforcement * fix(files): harden ownership lifecycle and realtime admission * test(files): complete Project detachment database fixture * test(files): seed required Project memberships in integration fixtures * fix(files): resolve lifecycle and search review findings * fix(realtime): fence file joins by owner-qualified room * fix(files): retain shared resources after creator deletion Keep durable workspace and Project files and file folders with a nullable live creator while preserving other creator cascades and native owner constraints. Require a creator at insertion and remove the original-creator snapshot schema and backfill. Accept missing creator attribution throughout workspace metadata, v2 serialization and UI, and authorize canonical shared file delivery against current membership. Preserve stored version authors independently. Exercise account departure/deletion, retained storage and history, rollback, and concurrent writes against real PostgreSQL. * fix(files): reconcile creator handoff with project ownership Keep shared file and folder creator references non-null by transferring them to validated successors during departure and account deletion. Discover Project-only references from prior departures, retain attribution while an environment still grants access, and transfer ownership and storage payers atomically when the final access is removed. Recheck the selected membership under lock before handoff so a concurrent replacement grant and its creator attribution remain untouched. Reconcile the unreleased creator migration and restore non-null API/CLI contracts. Integrates lifecycle817191c757and membership race fixbe01225427into the file foundation. * fix(files): preserve upload history across creator handoff * fix(files): align lifecycle fixtures and conflict responses * fix(files): preserve empty history and order lifecycle locks * fix(files): retry restore names claimed by legacy writers * fix(files): make staged cleanup safe across database failures * fix(files): clean staged content after rejected commits * fix(ci): resolve manual audit base from the open pull request * fix(tests): create Project membership in desktop and CLI fixtures * fix(files): bound affected subtrees and preserve fenced revisions * fix(ci): pin the current pull request base branch * fix(files): require workspace owners for workspace-scoped files * fix(db): make file ownership provisioning replay safe * fix(tests): restore Project enforcement fixtures after migration renumbering * fix(tests): scope migration probes and align remaining Project fixtures * feat(projects): prepare workspace project column compatibility * test(projects): clean up compatibility fixtures atomically * feat(projects): move membership to workspace column with rollout bridge * test(projects): align transfer mocks with workspace membership * test(projects): provision required membership in transfer unit fixtures * improvement(workspaces): present API responses explicitly * feat(projects): prepare legacy membership with a resumable operator tool * fix(projects): support PostgreSQL 16 column migration * fix(projects): allow multi-batch copies to finish * fix(projects): support PostgreSQL 16 preparation and current fixtures * fix(projects): reconcile memberships during schema push * fix(projects): enforce safe schema push provisioning * test(projects): provision newly merged workspace fixtures * fix(projects): use the direct connection for push reconciliation * test(billing): wait for parked transactions before racing writers * test(billing): freeze the clock for exact deadline assertions * fix(projects): close operator verification and contention gaps * test(billing): stabilize member ledger timeout checks * fix(projects): await cleanup and bound backfill artifacts * fix(projects): honor operator cancellation and status exits * fix(projects): reject verification of conflicted plans * fix(projects): defer archive repair on database contention * fix(projects): coordinate read-only maintenance commands * ci(projects): use the standard PostgreSQL test coverage * fix(projects): support trigger-free column rollout * fix(projects): run bounded membership backfill before enforcement * test(projects): verify column-only archive repair assignment * fix(projects): retain healthy indexes during schema push * ci(projects): use standard integration coverage for enforcement * fix(projects): correct rollout fixtures and schema-push index * fix(projects): reconcile assigned environments before enforcement * fix(projects): preserve backfill repair and resume guarantees Lock and verify effective legacy memberships before materializing reviewed assignments and applying the shared detach policy. Reject resume reports whose code hash differs before changing their checkpoint. Isolate local pubsub subscriber failures so healthy archive subscribers still receive notifications. Extend existing CLI and real-database integration coverage for mixed memberships, concurrent and stale connector changes, unchanged mismatched reports, replay, and local subscriber delivery. * test(projects): align fixture lifecycle with enforced project ownership * test(projects): skip archive repair suite when Redis is unset * chore(projects): normalize enforcement SQL whitespace * feat(projects): commit membership authority before reconciliation * fix(projects): switch membership authority after compatible rollout * test(projects): guard optional authority fixtures explicitly * test(projects): seed authority in billing lock-order mock * fix(projects): bound authority barriers and verify push replay * fix(projects): pin operator schema and pace detach repairs * docs(projects): record native constraint rollout decisions * refactor(projects): replace integrity triggers with native foreign keys * fix(projects): recognize completed rollout without its marker * fix(projects): retire rollout marker with legacy membership * test(projects): model expansion authority in workspace move fixtures * fix(projects): keep repair reads compatible with expansion schema * fix(projects): retain project name for workspace archival * docs(projects): consolidate permanent storage rules in README * fix(files): remove stale membership imports and trigger fixture * Bound historical Project repair fixture to compatible script migrations * Address ownership lifecycle and realtime review findings * Use compatible array copies for document identity sorting * Keep foundation owned-file creation on its available billing API * refactor: name the projects flag fallback PROJECTS * test: cover ordinary PR and squash push audit bases * ci: restore upstream audit base selection * fix(db): retry public share backfill contention without losing progress * refactor(db): fold creator lifetime guard into file ownership migration * test(files): narrow recorded database insert values * fix(files): preserve owned content and generated search delivery * fix(files): preserve active artifact indexing and narrow helpers * refactor(files): narrow ownership triggers and enforce folder edges with foreign keys * fix(realtime): preserve replacement documents during delayed joins * fix(files): provision composite folder keys before references * fix(db): correct dependency patch offsets for clean installs
205 lines
6.8 KiB
TypeScript
205 lines
6.8 KiB
TypeScript
import { spawnSync } from 'node:child_process'
|
|
import { tmpdir } from 'node:os'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { createLogger } from '@sim/logger'
|
|
import { sleep } from '@sim/utils/helpers'
|
|
import { generateId } from '@sim/utils/id'
|
|
|
|
/**
|
|
* Runs the real-infrastructure test layer (`*.integration.ts`) locally: `bun run test:integration`.
|
|
* Creates and removes its own Postgres and Redis containers, provisions the schema the way CI does,
|
|
* and runs `vitest run --mode integration` in `packages/db`, `apps/sim`, and `apps/realtime` with `TEST_DATABASE_URL`
|
|
* and `TEST_REDIS_URL`; it never reads an application DSN.
|
|
* Set INTEGRATION_DB_PROVISION=migrate to exercise the versioned SQL migration path.
|
|
* Set KNOWLEDGE_SCALE_TEST=true for the opt-in scale suite; its JSON report is saved in tmpdir.
|
|
* Optional positional `apps/sim` Vitest filename filters limit a diagnostic run (and skip
|
|
* `packages/db` and `apps/realtime`); omit them for full validation.
|
|
*/
|
|
const logger = createLogger('IntegrationTests')
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
const container = `sim-integration-test-${generateId()}`
|
|
const redisContainer = `${container}-redis`
|
|
const database = 'sim_test'
|
|
const provision = process.env.INTEGRATION_DB_PROVISION ?? 'push'
|
|
if (provision !== 'push' && provision !== 'migrate')
|
|
throw new Error('INTEGRATION_DB_PROVISION must be push or migrate')
|
|
const scale = process.env.KNOWLEDGE_SCALE_TEST === 'true'
|
|
const searchPerformance = process.env.KNOWLEDGE_SEARCH_PERFORMANCE_TEST === 'true'
|
|
const testFilters = process.argv.slice(2)
|
|
if (testFilters.some((filter) => filter.startsWith('-')) || (scale && testFilters.length)) {
|
|
throw new Error('Pass only filename filters, and do not combine them with the scale suite')
|
|
}
|
|
const keepDatabase =
|
|
(scale && process.env.KNOWLEDGE_SCALE_KEEP_DATABASE === 'true') ||
|
|
(process.env.KNOWLEDGE_SEARCH_PERFORMANCE_TEST === 'true' &&
|
|
process.env.KNOWLEDGE_SEARCH_PERFORMANCE_KEEP_DATABASE === 'true')
|
|
const scaleReportFile =
|
|
process.env.KNOWLEDGE_SCALE_REPORT_FILE ?? path.join(tmpdir(), `${container}.json`)
|
|
|
|
function run(
|
|
command: string,
|
|
args: string[],
|
|
options: { cwd?: string; env?: NodeJS.ProcessEnv; capture?: boolean } = {}
|
|
) {
|
|
const result = spawnSync(command, args, {
|
|
cwd: options.cwd ?? root,
|
|
env: options.env ?? process.env,
|
|
encoding: 'utf8',
|
|
stdio: options.capture ? 'pipe' : 'inherit',
|
|
})
|
|
if (result.status !== 0)
|
|
throw new Error(`${command} ${args[0]} failed (${result.status ?? result.error?.message})`)
|
|
return result.stdout?.trim() ?? ''
|
|
}
|
|
|
|
let started = false
|
|
let redisStarted = false
|
|
try {
|
|
run(
|
|
'docker',
|
|
[
|
|
'run',
|
|
'--rm',
|
|
'--detach',
|
|
...(scale
|
|
? ['--shm-size', '3g']
|
|
: searchPerformance
|
|
? ['--cpus', '2', '--memory', '1g', '--shm-size', '512m']
|
|
: []),
|
|
'--name',
|
|
container,
|
|
'--env',
|
|
'POSTGRES_HOST_AUTH_METHOD=trust',
|
|
'--publish',
|
|
'127.0.0.1::5432',
|
|
process.env.KNOWLEDGE_TEST_POSTGRES_IMAGE ?? 'pgvector/pgvector:pg17',
|
|
...(searchPerformance
|
|
? ['-c', 'shared_buffers=256MB', '-c', 'work_mem=8MB', '-c', 'maintenance_work_mem=256MB']
|
|
: []),
|
|
],
|
|
{ capture: true }
|
|
)
|
|
started = true
|
|
let ready = false
|
|
for (let attempt = 0; attempt < 60; attempt++) {
|
|
/** The image's initialization server accepts Unix sockets before restarting into its final TCP server. */
|
|
const result = spawnSync(
|
|
'docker',
|
|
['exec', container, 'pg_isready', '-h', '127.0.0.1', '-U', 'postgres'],
|
|
{ stdio: 'ignore' }
|
|
)
|
|
if (result.status === 0) {
|
|
ready = true
|
|
break
|
|
}
|
|
await sleep(500)
|
|
}
|
|
if (!ready) throw new Error('Disposable Postgres did not become ready')
|
|
run('docker', ['exec', container, 'createdb', '-U', 'postgres', database])
|
|
run('docker', [
|
|
'exec',
|
|
container,
|
|
'psql',
|
|
'-U',
|
|
'postgres',
|
|
'-d',
|
|
database,
|
|
'-v',
|
|
'ON_ERROR_STOP=1',
|
|
'-c',
|
|
'CREATE EXTENSION vector; CREATE EXTENSION btree_gin; CREATE EXTENSION pg_trgm',
|
|
])
|
|
const endpoint = run('docker', ['port', container, '5432/tcp'], { capture: true })
|
|
if (!/^127\.0\.0\.1:\d+$/.test(endpoint))
|
|
throw new Error('Unexpected disposable Postgres endpoint')
|
|
const databaseUrl = `postgresql://postgres@${endpoint}/${database}`
|
|
if (keepDatabase)
|
|
logger.info('Retaining disposable benchmark database for follow-up measurements', {
|
|
container,
|
|
databaseUrl,
|
|
})
|
|
run(
|
|
'docker',
|
|
[
|
|
'run',
|
|
'--rm',
|
|
'--detach',
|
|
'--name',
|
|
redisContainer,
|
|
'--publish',
|
|
'127.0.0.1::6379',
|
|
'redis:8.2-alpine',
|
|
'redis-server',
|
|
'--save',
|
|
'',
|
|
'--appendonly',
|
|
'no',
|
|
],
|
|
{ capture: true }
|
|
)
|
|
redisStarted = true
|
|
let redisReady = false
|
|
for (let attempt = 0; attempt < 60; attempt++) {
|
|
const result = spawnSync('docker', ['exec', redisContainer, 'redis-cli', 'ping'], {
|
|
stdio: 'ignore',
|
|
})
|
|
if (result.status === 0) {
|
|
redisReady = true
|
|
break
|
|
}
|
|
await sleep(500)
|
|
}
|
|
if (!redisReady) throw new Error('Disposable Redis did not become ready')
|
|
const redisEndpoint = run('docker', ['port', redisContainer, '6379/tcp'], { capture: true })
|
|
if (!/^127\.0\.0\.1:\d+$/.test(redisEndpoint))
|
|
throw new Error('Unexpected disposable Redis endpoint')
|
|
const environment = {
|
|
...process.env,
|
|
DATABASE_URL: databaseUrl,
|
|
MIGRATION_DATABASE_URL: databaseUrl,
|
|
TEST_DATABASE_URL: databaseUrl,
|
|
TEST_REDIS_URL: `redis://${redisEndpoint}`,
|
|
...(scale ? { KNOWLEDGE_SCALE_REPORT_FILE: scaleReportFile } : {}),
|
|
}
|
|
run('bun', ['run', `db:${provision}`], { cwd: path.join(root, 'packages/db'), env: environment })
|
|
run(
|
|
'bun',
|
|
[
|
|
'run',
|
|
'test',
|
|
'--mode',
|
|
'integration',
|
|
...(scale ? ['lib/knowledge/__integration__/scale.integration.ts'] : testFilters),
|
|
],
|
|
{
|
|
cwd: path.join(root, 'apps/sim'),
|
|
env: environment,
|
|
}
|
|
)
|
|
if (!scale && testFilters.length === 0) {
|
|
run('bun', ['run', 'test', '--mode', 'integration'], {
|
|
cwd: path.join(root, 'packages/db'),
|
|
env: environment,
|
|
})
|
|
run('bun', ['run', 'test', '--mode', 'integration'], {
|
|
cwd: path.join(root, 'apps/realtime'),
|
|
env: environment,
|
|
})
|
|
}
|
|
logger.info(
|
|
scale
|
|
? 'Opt-in knowledge scale measurements passed'
|
|
: testFilters.length > 0
|
|
? 'Selected disposable integration tests passed'
|
|
: 'Integration tests passed against disposable PostgreSQL and Redis'
|
|
)
|
|
if (scale) logger.info('Scale query plans and measurements', { reportFile: scaleReportFile })
|
|
} finally {
|
|
try {
|
|
if (redisStarted) run('docker', ['stop', redisContainer], { capture: true })
|
|
} finally {
|
|
if (started && !keepDatabase) run('docker', ['stop', container], { capture: true })
|
|
}
|
|
}
|