bunsane 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +445 -370
- package/core/BatchLoader.ts +56 -32
- package/core/Entity.ts +85 -1020
- package/core/EntityHookManager.ts +52 -754
- package/core/Logger.ts +10 -0
- package/core/RequestContext.ts +94 -85
- package/core/RequestLoaders.ts +98 -5
- package/core/SchedulerManager.ts +28 -600
- package/core/app/cors.ts +2 -11
- package/core/app/preparedStatementWarmup.ts +9 -49
- package/core/app/requestRouter.ts +9 -8
- package/core/app/restRegistry.ts +8 -0
- package/core/archetype/fieldResolvers.ts +85 -40
- package/core/archetype/relationLoader.ts +135 -92
- package/core/cache/CacheManager.ts +91 -302
- package/core/cache/CompressionUtils.ts +34 -3
- package/core/cache/MemoryCache.ts +40 -37
- package/core/cache/RedisCache.ts +4 -4
- package/core/cache/health.ts +30 -0
- package/core/cache/invalidation.ts +96 -0
- package/core/cache/strategies/writeInvalidate.ts +111 -0
- package/core/cache/strategies/writeThrough.ts +233 -0
- package/core/components/BaseComponent.ts +16 -8
- package/core/components/ComponentRegistry.ts +28 -0
- package/core/decorators/IndexedField.ts +1 -1
- package/core/entity/cacheStrategies.ts +97 -0
- package/core/entity/componentAccess.ts +364 -0
- package/core/entity/finders.ts +202 -0
- package/core/entity/pendingOps.ts +72 -0
- package/core/entity/saveEntity.ts +377 -0
- package/core/hooks/dispatcher.ts +439 -0
- package/core/hooks/guards.ts +155 -0
- package/core/hooks/registry.ts +247 -0
- package/core/metadata/definitions/Component.ts +1 -1
- package/core/metadata/index.ts +15 -4
- package/core/middleware/RateLimit.ts +102 -105
- package/core/middleware/RequestId.ts +2 -9
- package/core/middleware/SecurityHeaders.ts +2 -11
- package/core/middleware/headers.ts +28 -0
- package/core/remote/OutboxWorker.ts +213 -183
- package/core/remote/RemoteManager.ts +401 -400
- package/core/remote/types.ts +153 -151
- package/core/requestScope.ts +34 -0
- package/core/scheduler/cronEvaluator.ts +174 -0
- package/core/scheduler/lifecycleHooks.ts +21 -0
- package/core/scheduler/lockCoordinator.ts +27 -0
- package/core/scheduler/metrics.ts +14 -0
- package/core/scheduler/taskRunner.ts +420 -0
- package/database/DatabaseHelper.ts +128 -101
- package/database/IndexingStrategy.ts +72 -2
- package/database/PreparedStatementCache.ts +8 -2
- package/database/cancellable.ts +35 -22
- package/database/index.ts +15 -3
- package/database/instrumentedDb.ts +141 -141
- package/endpoints/archetypes.ts +2 -8
- package/endpoints/tables.ts +6 -1
- package/gql/index.ts +1 -1
- package/gql/visitors/ResolverGeneratorVisitor.ts +25 -4
- package/package.json +22 -1
- package/query/CTENode.ts +5 -3
- package/query/ComponentInclusionNode.ts +240 -13
- package/query/OrNode.ts +6 -5
- package/query/Query.ts +157 -46
- package/query/QueryContext.ts +6 -0
- package/query/QueryDAG.ts +7 -2
- package/query/membershipSource.ts +66 -0
- package/storage/LocalStorageProvider.ts +8 -3
- package/studio/dist/assets/index-BMZ67Npg.js +254 -0
- package/studio/dist/assets/index-BpbuYz9g.css +1 -0
- package/studio/{index.html → dist/index.html} +3 -2
- package/swagger/generator.ts +11 -1
- package/upload/UploadManager.ts +8 -6
- package/utils/uuid.ts +40 -10
- package/.claude/scheduled_tasks.lock +0 -1
- package/.claude/settings.local.json +0 -47
- package/.prettierrc +0 -4
- package/.serena/memories/architectural-decision-no-dependency-injection.md +0 -76
- package/.serena/memories/architecture.md +0 -154
- package/.serena/memories/cache-interface-refactoring-2026-01-24.md +0 -165
- package/.serena/memories/code_style_and_conventions.md +0 -76
- package/.serena/memories/project_overview.md +0 -43
- package/.serena/memories/schema-dsl-plan.md +0 -107
- package/.serena/memories/suggested_commands.md +0 -80
- package/.serena/memories/typescript-compilation-status.md +0 -54
- package/.serena/project.yml +0 -114
- package/BunSane.jpg +0 -0
- package/CLAUDE.md +0 -198
- package/TODO.md +0 -2
- package/bun.lock +0 -302
- package/bunfig.toml +0 -10
- package/docs/RFC_APP_REFACTOR.md +0 -248
- package/docs/RFC_REFACTOR_TARGETS.md +0 -251
- package/docs/SCALABILITY_PLAN.md +0 -175
- package/studio/bun.lock +0 -482
- package/studio/package.json +0 -39
- package/studio/postcss.config.js +0 -6
- package/studio/src/components/DataTable.tsx +0 -211
- package/studio/src/components/Layout.tsx +0 -13
- package/studio/src/components/PageContainer.tsx +0 -9
- package/studio/src/components/PageHeader.tsx +0 -13
- package/studio/src/components/SearchBar.tsx +0 -57
- package/studio/src/components/Sidebar.tsx +0 -294
- package/studio/src/components/ui/button.tsx +0 -56
- package/studio/src/components/ui/checkbox.tsx +0 -26
- package/studio/src/components/ui/input.tsx +0 -25
- package/studio/src/hooks/useDataTable.ts +0 -131
- package/studio/src/index.css +0 -36
- package/studio/src/lib/api.ts +0 -186
- package/studio/src/lib/utils.ts +0 -13
- package/studio/src/main.tsx +0 -17
- package/studio/src/pages/ArcheType.tsx +0 -239
- package/studio/src/pages/Components.tsx +0 -124
- package/studio/src/pages/EntityInspector.tsx +0 -302
- package/studio/src/pages/QueryRunner.tsx +0 -246
- package/studio/src/pages/Table.tsx +0 -94
- package/studio/src/pages/Welcome.tsx +0 -241
- package/studio/src/routes.tsx +0 -45
- package/studio/src/store/archeTypeSettings.ts +0 -30
- package/studio/src/store/studio.ts +0 -65
- package/studio/src/utils/columnHelpers.tsx +0 -114
- package/studio/studio-instructions.md +0 -81
- package/studio/tailwind.config.js +0 -77
- package/studio/utils.ts +0 -54
- package/studio/vite.config.js +0 -19
- package/tests/benchmark/BENCHMARK_DATABASES_PLAN.md +0 -338
- package/tests/benchmark/bunfig.toml +0 -9
- package/tests/benchmark/fixtures/EcommerceComponents.ts +0 -283
- package/tests/benchmark/fixtures/EcommerceDataGenerators.ts +0 -301
- package/tests/benchmark/fixtures/RelationTracker.ts +0 -159
- package/tests/benchmark/fixtures/index.ts +0 -6
- package/tests/benchmark/index.ts +0 -22
- package/tests/benchmark/noop-preload.ts +0 -3
- package/tests/benchmark/query-lateral-benchmark.test.ts +0 -372
- package/tests/benchmark/runners/BenchmarkLoader.ts +0 -132
- package/tests/benchmark/runners/index.ts +0 -4
- package/tests/benchmark/scenarios/query-benchmarks.test.ts +0 -465
- package/tests/benchmark/scripts/generate-db.ts +0 -344
- package/tests/benchmark/scripts/run-benchmarks.ts +0 -97
- package/tests/e2e/http.test.ts +0 -130
- package/tests/fixtures/archetypes/TestUserArchetype.ts +0 -21
- package/tests/fixtures/components/TestOrder.ts +0 -23
- package/tests/fixtures/components/TestProduct.ts +0 -23
- package/tests/fixtures/components/TestUser.ts +0 -20
- package/tests/fixtures/components/index.ts +0 -6
- package/tests/graphql/SchemaGeneration.test.ts +0 -90
- package/tests/graphql/builders/ResolverBuilder.test.ts +0 -223
- package/tests/graphql/builders/TypeDefBuilder.test.ts +0 -153
- package/tests/helpers/MockRedisClient.ts +0 -113
- package/tests/helpers/MockRedisStreamServer.ts +0 -448
- package/tests/integration/archetype/ArcheType.persistence.test.ts +0 -241
- package/tests/integration/cache/CacheInvalidation.test.ts +0 -259
- package/tests/integration/entity/Entity.persistence.test.ts +0 -333
- package/tests/integration/entity/Entity.saveTimeout.test.ts +0 -110
- package/tests/integration/loaders/RequestLoaders.abort.test.ts +0 -82
- package/tests/integration/query/Query.abort.test.ts +0 -66
- package/tests/integration/query/Query.complexAnalysis.test.ts +0 -557
- package/tests/integration/query/Query.edgeCases.test.ts +0 -595
- package/tests/integration/query/Query.exec.test.ts +0 -576
- package/tests/integration/query/Query.explainAnalyze.test.ts +0 -233
- package/tests/integration/query/Query.jsonbArray.test.ts +0 -214
- package/tests/integration/remote/dlq.test.ts +0 -175
- package/tests/integration/remote/event-dispatch.test.ts +0 -114
- package/tests/integration/remote/outbox.test.ts +0 -130
- package/tests/integration/remote/rpc.test.ts +0 -177
- package/tests/pglite-setup.ts +0 -62
- package/tests/setup.ts +0 -164
- package/tests/stress/BenchmarkRunner.ts +0 -203
- package/tests/stress/DataSeeder.ts +0 -190
- package/tests/stress/StressTestReporter.ts +0 -229
- package/tests/stress/cursor-perf-test.ts +0 -171
- package/tests/stress/fixtures/RealisticComponents.ts +0 -235
- package/tests/stress/fixtures/StressTestComponents.ts +0 -58
- package/tests/stress/index.ts +0 -7
- package/tests/stress/scenarios/query-benchmarks.test.ts +0 -285
- package/tests/stress/scenarios/realistic-scenarios.test.ts +0 -1081
- package/tests/stress/scenarios/timeout-investigation.test.ts +0 -522
- package/tests/unit/BatchLoader.test.ts +0 -196
- package/tests/unit/archetype/ArcheType.test.ts +0 -107
- package/tests/unit/cache/CacheManager.test.ts +0 -498
- package/tests/unit/cache/MemoryCache.test.ts +0 -260
- package/tests/unit/cache/RedisCache.test.ts +0 -411
- package/tests/unit/database/cancellable.test.ts +0 -81
- package/tests/unit/database/instrumentedDb.test.ts +0 -160
- package/tests/unit/entity/Entity.components.test.ts +0 -317
- package/tests/unit/entity/Entity.drainSideEffects.test.ts +0 -51
- package/tests/unit/entity/Entity.reload.test.ts +0 -63
- package/tests/unit/entity/Entity.requireComponents.test.ts +0 -72
- package/tests/unit/entity/Entity.test.ts +0 -345
- package/tests/unit/gql/depthLimit.test.ts +0 -203
- package/tests/unit/gql/operationMiddleware.test.ts +0 -293
- package/tests/unit/health/Health.test.ts +0 -129
- package/tests/unit/middleware/AccessLog.test.ts +0 -37
- package/tests/unit/middleware/Middleware.test.ts +0 -98
- package/tests/unit/middleware/RequestId.test.ts +0 -54
- package/tests/unit/middleware/SecurityHeaders.test.ts +0 -66
- package/tests/unit/query/FilterBuilder.test.ts +0 -111
- package/tests/unit/query/JsonbArrayBuilder.test.ts +0 -178
- package/tests/unit/query/Query.emptyString.test.ts +0 -69
- package/tests/unit/query/Query.test.ts +0 -310
- package/tests/unit/remote/CircuitBreaker.test.ts +0 -159
- package/tests/unit/remote/RemoteError.test.ts +0 -55
- package/tests/unit/remote/decorators.test.ts +0 -195
- package/tests/unit/remote/metrics.test.ts +0 -115
- package/tests/unit/remote/mockRedisStreamServer.test.ts +0 -104
- package/tests/unit/scheduler/DistributedLock.test.ts +0 -274
- package/tests/unit/scheduler/SchedulerManager.timeBased.test.ts +0 -95
- package/tests/unit/schema/schema-integration.test.ts +0 -426
- package/tests/unit/schema/schema.test.ts +0 -580
- package/tests/unit/storage/S3StorageProvider.test.ts +0 -567
- package/tests/unit/upload/RestUpload.test.ts +0 -267
- package/tests/unit/validateEnv.test.ts +0 -82
- package/tests/utils/entity-tracker.ts +0 -57
- package/tests/utils/index.ts +0 -13
- package/tests/utils/test-context.ts +0 -149
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for Entity.save timeout and cancellation behavior.
|
|
3
|
-
*
|
|
4
|
-
* Regression coverage for the production incident where Entity.save's wall-
|
|
5
|
-
* clock timeout rejected the outer Promise but left the underlying Bun SQL
|
|
6
|
-
* transaction mid-flight. Under pgbouncer transaction-mode pooling this
|
|
7
|
-
* leaked backend PostgreSQL sessions into `idle in transaction` state,
|
|
8
|
-
* exhausting the pool.
|
|
9
|
-
*
|
|
10
|
-
* These tests prove the invariants the fix must uphold:
|
|
11
|
-
* 1. An aborted save leaves no partial rows — Bun SQL's transaction callback
|
|
12
|
-
* throws, auto-ROLLBACK fires, backend connection is released.
|
|
13
|
-
* 2. The connection pool stays healthy after repeated aborts — subsequent
|
|
14
|
-
* saves on fresh entities still succeed.
|
|
15
|
-
* 3. A save with no abort still commits normally.
|
|
16
|
-
*
|
|
17
|
-
* The wall-clock DB_QUERY_TIMEOUT path is module-cached at import time so it
|
|
18
|
-
* is not exercised here directly. Manual verification on a real Postgres +
|
|
19
|
-
* pgbouncer stack (with query_wait_timeout short enough to fire) should
|
|
20
|
-
* confirm pg_stat_activity shows no `idle in transaction` backends after
|
|
21
|
-
* this test suite runs. See the handoff doc (2026-04-18) for the repro steps.
|
|
22
|
-
*/
|
|
23
|
-
import { describe, test, expect, beforeAll } from 'bun:test';
|
|
24
|
-
import { Entity } from '../../../core/Entity';
|
|
25
|
-
import db from '../../../database';
|
|
26
|
-
import { TestUser } from '../../fixtures/components';
|
|
27
|
-
import { createTestContext, ensureComponentsRegistered } from '../../utils';
|
|
28
|
-
|
|
29
|
-
describe('Entity.save timeout and cancellation', () => {
|
|
30
|
-
const ctx = createTestContext();
|
|
31
|
-
|
|
32
|
-
beforeAll(async () => {
|
|
33
|
-
await ensureComponentsRegistered(TestUser);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('aborted doSave does not leave partial rows (transaction rolls back)', async () => {
|
|
37
|
-
const entity = ctx.tracker.create();
|
|
38
|
-
entity.add(TestUser, { name: 'aborted', email: 'a@example.com', age: 1 });
|
|
39
|
-
|
|
40
|
-
const controller = new AbortController();
|
|
41
|
-
// Abort immediately — the first in-flight query will be cancelled,
|
|
42
|
-
// the transaction callback throws, Bun SQL issues ROLLBACK.
|
|
43
|
-
queueMicrotask(() => controller.abort(new Error('simulated save timeout')));
|
|
44
|
-
|
|
45
|
-
const result = db.transaction(async (trx) => {
|
|
46
|
-
await entity.doSave(trx, controller.signal);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
await expect(result).rejects.toBeDefined();
|
|
50
|
-
|
|
51
|
-
// Entity must NOT exist — rollback invariant.
|
|
52
|
-
const rows = await db`SELECT id FROM entities WHERE id = ${entity.id}`;
|
|
53
|
-
expect(rows.length).toBe(0);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('connection pool stays healthy after multiple aborted saves', async () => {
|
|
57
|
-
// Repeatedly abort saves — if connections leaked, subsequent saves
|
|
58
|
-
// would eventually block on pool acquire.
|
|
59
|
-
for (let i = 0; i < 8; i++) {
|
|
60
|
-
const entity = Entity.Create();
|
|
61
|
-
entity.add(TestUser, { name: `aborted-${i}`, email: `a${i}@e.com`, age: i });
|
|
62
|
-
|
|
63
|
-
const controller = new AbortController();
|
|
64
|
-
queueMicrotask(() => controller.abort(new Error('simulated timeout')));
|
|
65
|
-
|
|
66
|
-
await db.transaction(async (trx) => {
|
|
67
|
-
await entity.doSave(trx, controller.signal);
|
|
68
|
-
}).catch(() => { /* expected */ });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// A fresh save must still succeed on the pool that serviced the aborts.
|
|
72
|
-
const healthy = ctx.tracker.create();
|
|
73
|
-
healthy.add(TestUser, { name: 'healthy', email: 'h@e.com', age: 99 });
|
|
74
|
-
await healthy.save();
|
|
75
|
-
|
|
76
|
-
expect(healthy._persisted).toBe(true);
|
|
77
|
-
|
|
78
|
-
const rows = await db`SELECT id FROM entities WHERE id = ${healthy.id}`;
|
|
79
|
-
expect(rows.length).toBe(1);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('doSave without signal behaves normally (backwards compatible)', async () => {
|
|
83
|
-
const entity = ctx.tracker.create();
|
|
84
|
-
entity.add(TestUser, { name: 'no-signal', email: 'n@e.com', age: 5 });
|
|
85
|
-
|
|
86
|
-
await db.transaction(async (trx) => {
|
|
87
|
-
await entity.doSave(trx); // no signal passed
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const rows = await db`SELECT id FROM entities WHERE id = ${entity.id}`;
|
|
91
|
-
expect(rows.length).toBe(1);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test('save() resolves even if post-commit cache work is slow (fire-and-forget)', async () => {
|
|
95
|
-
// Cache handler is queued via queueMicrotask; save() must resolve as
|
|
96
|
-
// soon as the DB transaction commits. We assert save resolves quickly
|
|
97
|
-
// even though handleCacheAfterSave is awaited separately.
|
|
98
|
-
const entity = ctx.tracker.create();
|
|
99
|
-
entity.add(TestUser, { name: 'fast', email: 'f@e.com', age: 10 });
|
|
100
|
-
|
|
101
|
-
const start = performance.now();
|
|
102
|
-
await entity.save();
|
|
103
|
-
const elapsed = performance.now() - start;
|
|
104
|
-
|
|
105
|
-
expect(entity._persisted).toBe(true);
|
|
106
|
-
// Generous bound — if cache were blocking save, timings under load
|
|
107
|
-
// could stretch past the budget. This just guards gross regressions.
|
|
108
|
-
expect(elapsed).toBeLessThan(5000);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for `createRequestLoaders` AbortSignal threading.
|
|
3
|
-
*
|
|
4
|
-
* The GraphQL request plugin (core/RequestContext.ts) wires the request's
|
|
5
|
-
* AbortSignal into each DataLoader's `db.unsafe()` call via timedUnsafe.
|
|
6
|
-
* On abort the in-flight query is cancelled, releasing the backend
|
|
7
|
-
* connection back to pgbouncer.
|
|
8
|
-
*/
|
|
9
|
-
import { describe, test, expect, beforeAll, beforeEach } from 'bun:test';
|
|
10
|
-
import db from '../../../database';
|
|
11
|
-
import { Entity } from '../../../core/Entity';
|
|
12
|
-
import { createRequestLoaders } from '../../../core/RequestLoaders';
|
|
13
|
-
import { ComponentRegistry } from '../../../core/components';
|
|
14
|
-
import { TestUser } from '../../fixtures/components';
|
|
15
|
-
import { createTestContext, ensureComponentsRegistered } from '../../utils';
|
|
16
|
-
|
|
17
|
-
describe('RequestLoaders AbortSignal', () => {
|
|
18
|
-
const ctx = createTestContext();
|
|
19
|
-
let seededEntity: Entity;
|
|
20
|
-
let testUserTypeId: string;
|
|
21
|
-
|
|
22
|
-
beforeAll(async () => {
|
|
23
|
-
await ensureComponentsRegistered(TestUser);
|
|
24
|
-
testUserTypeId = ComponentRegistry.getComponentId('TestUser')!;
|
|
25
|
-
expect(testUserTypeId).toBeTruthy();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
beforeEach(async () => {
|
|
29
|
-
// Fresh seed per test — createTestContext's afterEach cleans tracked
|
|
30
|
-
// entities, so seeds set up once would disappear after the first
|
|
31
|
-
// test in the suite runs.
|
|
32
|
-
seededEntity = ctx.tracker.create();
|
|
33
|
-
seededEntity.add(TestUser, { name: 'loader-seed', email: 'l@e.com', age: 1 });
|
|
34
|
-
await seededEntity.save();
|
|
35
|
-
await Entity.drainPendingSideEffects();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('entityById loader rejects when pre-aborted', async () => {
|
|
39
|
-
const controller = new AbortController();
|
|
40
|
-
controller.abort(new Error('pre-aborted'));
|
|
41
|
-
|
|
42
|
-
const loaders = createRequestLoaders(db, undefined, controller.signal);
|
|
43
|
-
await expect(loaders.entityById.load(seededEntity.id)).rejects.toBeDefined();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('componentsByEntityType loader rejects when pre-aborted', async () => {
|
|
47
|
-
const controller = new AbortController();
|
|
48
|
-
controller.abort(new Error('pre-aborted'));
|
|
49
|
-
|
|
50
|
-
const loaders = createRequestLoaders(db, undefined, controller.signal);
|
|
51
|
-
await expect(
|
|
52
|
-
loaders.componentsByEntityType.load({
|
|
53
|
-
entityId: seededEntity.id,
|
|
54
|
-
typeId: testUserTypeId,
|
|
55
|
-
}),
|
|
56
|
-
).rejects.toBeDefined();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('loaders without signal still work (backwards compatible)', async () => {
|
|
60
|
-
const loaders = createRequestLoaders(db);
|
|
61
|
-
const ent = await loaders.entityById.load(seededEntity.id);
|
|
62
|
-
expect(ent?.id).toBe(seededEntity.id);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('perRequest counters track DataLoader invocations', async () => {
|
|
66
|
-
const perRequest = {
|
|
67
|
-
dbQueryCount: 0,
|
|
68
|
-
dataLoaderCalls: { entity: 0, component: 0, relation: 0 },
|
|
69
|
-
};
|
|
70
|
-
const loaders = createRequestLoaders(db, undefined, undefined, perRequest);
|
|
71
|
-
|
|
72
|
-
await loaders.entityById.load(seededEntity.id);
|
|
73
|
-
await loaders.componentsByEntityType.load({
|
|
74
|
-
entityId: seededEntity.id,
|
|
75
|
-
typeId: testUserTypeId,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
expect(perRequest.dataLoaderCalls.entity).toBeGreaterThanOrEqual(1);
|
|
79
|
-
expect(perRequest.dataLoaderCalls.component).toBeGreaterThanOrEqual(1);
|
|
80
|
-
expect(perRequest.dbQueryCount).toBeGreaterThan(0);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for Query.exec / Query.count AbortSignal propagation.
|
|
3
|
-
*
|
|
4
|
-
* The framework wall-clock timeout (core/app/requestRouter.ts) aborts a
|
|
5
|
-
* controller on 30s. The plugin in core/RequestContext.ts threads the
|
|
6
|
-
* request's AbortSignal into Query.exec via `{ signal }` options. These
|
|
7
|
-
* tests prove the abort actually cancels the underlying Bun SQL query
|
|
8
|
-
* (releasing the pgbouncer-backed connection) rather than just rejecting
|
|
9
|
-
* the outer promise.
|
|
10
|
-
*/
|
|
11
|
-
import { describe, test, expect, beforeAll } from 'bun:test';
|
|
12
|
-
import { Query } from '../../../query/Query';
|
|
13
|
-
import { TestUser } from '../../fixtures/components';
|
|
14
|
-
import { createTestContext, ensureComponentsRegistered } from '../../utils';
|
|
15
|
-
|
|
16
|
-
describe('Query AbortSignal propagation', () => {
|
|
17
|
-
const ctx = createTestContext();
|
|
18
|
-
|
|
19
|
-
beforeAll(async () => {
|
|
20
|
-
await ensureComponentsRegistered(TestUser);
|
|
21
|
-
|
|
22
|
-
// Seed a small dataset so queries actually hit the DB.
|
|
23
|
-
for (let i = 0; i < 5; i++) {
|
|
24
|
-
const e = ctx.tracker.create();
|
|
25
|
-
e.add(TestUser, { name: `abort-seed-${i}`, email: `a${i}@e.com`, age: i });
|
|
26
|
-
await e.save();
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('exec() with pre-aborted signal rejects without running query', async () => {
|
|
31
|
-
const controller = new AbortController();
|
|
32
|
-
controller.abort(new Error('pre-aborted'));
|
|
33
|
-
|
|
34
|
-
const promise = new Query().with(TestUser).exec({ signal: controller.signal });
|
|
35
|
-
await expect(promise).rejects.toBeDefined();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('exec() rejects when signal aborts mid-flight', async () => {
|
|
39
|
-
const controller = new AbortController();
|
|
40
|
-
queueMicrotask(() => controller.abort(new Error('mid-flight')));
|
|
41
|
-
|
|
42
|
-
const promise = new Query().with(TestUser).exec({ signal: controller.signal });
|
|
43
|
-
await expect(promise).rejects.toBeDefined();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('exec() without signal still works (backwards compatible)', async () => {
|
|
47
|
-
const rows = await new Query().with(TestUser).take(5).exec();
|
|
48
|
-
expect(Array.isArray(rows)).toBe(true);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('count() respects signal abort', async () => {
|
|
52
|
-
const controller = new AbortController();
|
|
53
|
-
controller.abort(new Error('pre-aborted'));
|
|
54
|
-
|
|
55
|
-
const promise = new Query().with(TestUser).count({ signal: controller.signal });
|
|
56
|
-
await expect(promise).rejects.toBeDefined();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('perRequest counters increment when supplied', async () => {
|
|
60
|
-
const perRequest = { dbQueryCount: 0 };
|
|
61
|
-
await new Query().with(TestUser).take(5).exec({ perRequest });
|
|
62
|
-
// Exec performs at least one DB query (count guard / select). Real
|
|
63
|
-
// count depends on prepared-cache state; assert non-zero only.
|
|
64
|
-
expect(perRequest.dbQueryCount).toBeGreaterThan(0);
|
|
65
|
-
});
|
|
66
|
-
});
|