@animastor/orchestration 0.3.4 → 1.0.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.md +31 -0
  3. package/package.json +11 -8
  4. package/src/gen/accept.js +370 -0
  5. package/src/gen/claim.js +155 -0
  6. package/src/gen/commands.js +338 -0
  7. package/src/gen/index.js +107 -0
  8. package/src/gen/local-runner.js +80 -0
  9. package/src/gen/ports.js +163 -0
  10. package/src/gen/progress.js +99 -0
  11. package/src/gen/sql/001-gen-core.js +130 -0
  12. package/src/gen/sql/002-command-jobs.js +58 -0
  13. package/src/gen/sql/003-scope-scenes.js +38 -0
  14. package/src/gen/sql/index.js +35 -0
  15. package/src/gen/sweeper.js +141 -0
  16. package/src/gen/util.js +136 -0
  17. package/src/gen/validate-media.js +181 -0
  18. package/src/index.js +15 -91
  19. package/src/legacy/index.js +100 -0
  20. package/src/{orchestration → legacy/orchestration}/scene-orchestrator.js +37 -3
  21. package/src/{runtime → legacy/runtime}/command-gate.js +83 -2
  22. package/src/{runtime → legacy/runtime}/counter-reconciliation.js +119 -1
  23. package/src/{runtime → legacy/runtime}/dispatch-engine.js +61 -0
  24. package/src/{runtime → legacy/runtime}/persistence-port.js +21 -0
  25. package/src/{runtime → legacy/runtime}/progress-events-port.js +4 -0
  26. package/src/{runtime → legacy/runtime}/reconciliation-engine.js +58 -1
  27. package/src/{runtime → legacy/runtime}/runtime-scheduler.js +53 -0
  28. package/src/{runtime → legacy/runtime}/scene-window.js +4 -0
  29. package/src/{runtime → legacy/runtime}/worker-health.js +11 -0
  30. package/test/artifact-root-binding.test.js +0 -174
  31. package/test/capacity-deferral.test.js +0 -265
  32. package/test/counter-reconciliation.test.js +0 -164
  33. package/test/mocks/redis-mock.js +0 -221
  34. package/test/stage146-d1-artifact-naming.test.js +0 -103
  35. package/test/stage147-a1-null-build-gate.test.js +0 -211
  36. package/test/test-bindings.js +0 -60
  37. /package/src/{host → legacy/host}/host-bindings.js +0 -0
  38. /package/src/{orchestration → legacy/orchestration}/index.js +0 -0
  39. /package/src/{orchestration → legacy/orchestration}/orchestrator.js +0 -0
  40. /package/src/{orchestration → legacy/orchestration}/runtime-result-consumer.js +0 -0
  41. /package/src/{orchestration → legacy/orchestration}/scene-callbacks.js +0 -0
  42. /package/src/{orchestration → legacy/orchestration}/scene-restoration.js +0 -0
  43. /package/src/{orchestration → legacy/orchestration}/scene-utils.js +0 -0
  44. /package/src/{runtime → legacy/runtime}/active-scenes-index.js +0 -0
  45. /package/src/{runtime → legacy/runtime}/audio-fsm-port.js +0 -0
  46. /package/src/{runtime → legacy/runtime}/circuit-breaker.js +0 -0
  47. /package/src/{runtime → legacy/runtime}/dispatch-outcomes.js +0 -0
  48. /package/src/{runtime → legacy/runtime}/failure-taxonomy.js +0 -0
  49. /package/src/{runtime → legacy/runtime}/hub-cancel-port.js +0 -0
  50. /package/src/{runtime → legacy/runtime}/layer-config-port.js +0 -0
  51. /package/src/{runtime → legacy/runtime}/lease-manager.js +0 -0
  52. /package/src/{runtime → legacy/runtime}/placeholder-audio-port.js +0 -0
  53. /package/src/{runtime → legacy/runtime}/retry-budget-manager.js +0 -0
  54. /package/src/{runtime → legacy/runtime}/runtime-metrics.js +0 -0
  55. /package/src/{runtime → legacy/runtime}/runtime-result-emitter.js +0 -0
  56. /package/src/{runtime → legacy/runtime}/scene-data-port.js +0 -0
  57. /package/src/{runtime → legacy/runtime}/video-fsm-port.js +0 -0
@@ -1,211 +0,0 @@
1
- // ======================================================
2
- // STAGE 147 — A1 REGRESSION: version-gate must see the build_id IS NULL row
3
- // ======================================================
4
- // A1 (stage146 §5.4): the key's only scene_assets row had build_id = NULL.
5
- // completeStage read the asset via sceneAssets.getAsset(..., buildId) —
6
- // which filters `build_id = $5` — so the row was invisible; markReady, the
7
- // ONLY writer able to stamp build_id (buildIdFromArtifactPath), runs BEHIND
8
- // the gate. Result: endless DIRTY + re-dispatch every 5 s scheduler tick
9
- // (cache_hit → callback → "stale" → DIRTY).
10
- //
11
- // The fix (orchestrator.completeStage): when the build-scoped read misses,
12
- // perform exactly ONE additional read of the SAME key with build_id IS NULL
13
- // (port op sceneAssets.getAssetNullBuild — never another build's row, never
14
- // "latest any row"), apply the SAME version rules, then let markReady stamp
15
- // build_id as before.
16
- //
17
- // On the PRE-FIX code tests 1 and 2 FAIL (gate stays DIRTY / fallback op
18
- // never consulted); they PASS with the fix. Fail-closed on PG errors is
19
- // preserved for both reads.
20
- // ======================================================
21
-
22
- const { expect } = require('chai');
23
- const { bindHostModules } = require('../src/host/host-bindings');
24
- const {
25
- OPS, setPersistencePort, _resetPersistencePort,
26
- } = require('../src/runtime/persistence-port');
27
- const { createMockRedis } = require('./mocks/redis-mock');
28
-
29
- const ORCH = require.resolve('../src/orchestration/orchestrator');
30
- const CALLBACKS = require.resolve('../src/orchestration/scene-callbacks');
31
- const DISPATCH = require.resolve('../src/runtime/dispatch-engine');
32
-
33
- const BOOK = 'book-a1';
34
- const CHAPTER = 'ch-a1';
35
- const SCENE = 'sc-a1';
36
- const BUILD = 'build_a1';
37
- const ARTIFACT = `/data/output/${BUILD}/scene_a1.png`;
38
- const SCENE_VERSIONS = [{ content_version: 5, audio_config_version: 5 }];
39
-
40
- // Port adapter built from the declared OPS (contract completeness is
41
- // asserted implicitly: setPersistencePort fails fast on any missing op).
42
- function makeAdapter(overrides = {}) {
43
- const adapter = {};
44
- for (const op of OPS) {
45
- const noop = async () => null;
46
- const [ns, fn] = op.includes('.') ? op.split('.') : [null, op];
47
- if (ns === null) adapter[fn] = overrides[op] || noop;
48
- else {
49
- adapter[ns] = adapter[ns] || {};
50
- adapter[ns][fn] = (overrides[op]) || noop;
51
- }
52
- }
53
- return adapter;
54
- }
55
-
56
- describe('Stage 147 — A1: version-gate fallback на строку build_id IS NULL (пакет)', function () {
57
- this.timeout(10000);
58
-
59
- let redis;
60
- let calls;
61
- let savedCache;
62
-
63
- function stubModule(resolvedPath, exports) {
64
- savedCache.set(resolvedPath, require.cache[resolvedPath]);
65
- require.cache[resolvedPath] = { exports, loaded: true };
66
- }
67
-
68
- beforeEach(() => {
69
- redis = createMockRedis();
70
- calls = { markReady: [], nullBuildReads: [] };
71
- savedCache = new Map();
72
- for (const p of [CALLBACKS, DISPATCH]) {
73
- savedCache.set(p, require.cache[p]);
74
- delete require.cache[p];
75
- }
76
-
77
- // Host seams the gate path touches (state restore after READY).
78
- bindHostModules({
79
- config: () => ({ OUTPUT_DIR: '/data/output' }),
80
- state: () => ({
81
- AssetState: {
82
- NEW: 'new', DIRTY: 'dirty', PENDING: 'pending',
83
- GENERATING: 'generating', READY: 'ready', FAILED: 'failed',
84
- },
85
- unsafeRestoreAssetState: async (r, b, c, s, asset, status) => {
86
- calls.stateWrite = { asset, status };
87
- },
88
- }),
89
- journal: () => ({ EventType: {}, appendSceneEvent: async () => {} }),
90
- });
91
-
92
- stubModule(CALLBACKS, {
93
- STAGE_HANDLERS: {
94
- image: async () => ({ ok: true, artifact: { buildId: BUILD, path: ARTIFACT } }),
95
- },
96
- });
97
- stubModule(DISPATCH, {
98
- verifyDispatchIdentity: async () => ({ valid: true, metadata: {} }),
99
- finalizeDispatch: async (r, b, c, s, stage, opts) => {
100
- calls.finalize = { stage, opts };
101
- return { finalized: true };
102
- },
103
- });
104
-
105
- setPersistencePort(makeAdapter({
106
- 'sceneVersions.getSceneVersions': async () => SCENE_VERSIONS,
107
- 'sceneAssets.getAsset': async () => (calls.buildRow === undefined ? null : calls.buildRow),
108
- 'sceneAssets.getAssetNullBuild': async (...args) => {
109
- calls.nullBuildReads.push(args);
110
- if (calls.nullRowError) throw calls.nullRowError;
111
- return calls.nullRow || null;
112
- },
113
- 'sceneAssets.markReady': async (...args) => {
114
- calls.markReady.push(args);
115
- return { status: 'ready' };
116
- },
117
- }));
118
- });
119
-
120
- afterEach(() => {
121
- for (const [p, entry] of savedCache) {
122
- if (entry) require.cache[p] = entry;
123
- else delete require.cache[p];
124
- }
125
- _resetPersistencePort();
126
- calls = {};
127
- // Возврат fail-fast дефолтов из test/test-bindings.js
128
- bindHostModules({
129
- journal: () => {
130
- throw new Error('[ORCH-TEST-BINDINGS] host journal not wired — wire it in the test that asserts journal behavior');
131
- },
132
- });
133
- });
134
-
135
- async function runGate(stage = 'image') {
136
- const orchestrator = require(ORCH);
137
- return orchestrator.completeStage(redis, BOOK, CHAPTER, SCENE, stage, BUILD, 'dispatch-a1');
138
- }
139
-
140
- it('1. NULL-строка с подтверждённой версией → READY с одного вызова, markReady вызван', async () => {
141
- calls.buildRow = null; // getAsset(buildId) промахнулся
142
- calls.nullRow = { build_id: null, scene_content_version: 5, scene_audio_config_version: 5 };
143
-
144
- const result = await runGate();
145
-
146
- expect(result.completed, 'fallback-чтение должно пропустить READY').to.be.true;
147
- expect(calls.markReady).to.have.length(1);
148
- expect(calls.markReady[0].slice(0, 5)).to.deep.equal([BOOK, CHAPTER, SCENE, 'image', ARTIFACT]);
149
- expect(calls.nullBuildReads, 'дополнительное чтение — ровно одно').to.have.length(1);
150
- expect(calls.nullBuildReads[0]).to.deep.equal([BOOK, CHAPTER, SCENE, 'image']);
151
- expect(calls.stateWrite).to.deep.equal({ asset: 'image', status: 'ready' });
152
- expect(calls.finalize.opts.outcome).to.equal('success');
153
- });
154
-
155
- it('2. NULL-строка с устаревшей версией (2 < 5) → не READY', async () => {
156
- calls.buildRow = null;
157
- calls.nullRow = { build_id: null, scene_content_version: 2, scene_audio_config_version: 2 };
158
-
159
- const result = await runGate();
160
-
161
- expect(result.completed).to.be.false;
162
- expect(result.reason).to.equal('stale');
163
- expect(calls.markReady).to.have.length(0);
164
- expect(calls.stateWrite).to.deep.equal({ asset: 'image', status: 'dirty' });
165
- });
166
-
167
- it('3. строки этого билда нет, NULL-строки нет (только чужой билд) → не READY', async () => {
168
- calls.buildRow = null;
169
- calls.nullRow = null;
170
-
171
- const result = await runGate();
172
-
173
- expect(result.completed).to.be.false;
174
- expect(result.reason).to.equal('stale');
175
- expect(calls.markReady).to.have.length(0);
176
- expect(calls.nullBuildReads).to.have.length(1);
177
- });
178
-
179
- it('4. строка этого билда найдена → fallback не выполняется', async () => {
180
- calls.buildRow = { build_id: BUILD, scene_content_version: 5, scene_audio_config_version: 5 };
181
- calls.nullRow = { build_id: null, scene_content_version: 5, scene_audio_config_version: 5 };
182
-
183
- const result = await runGate();
184
-
185
- expect(result.completed).to.be.true;
186
- expect(calls.nullBuildReads).to.have.length(0);
187
- expect(calls.markReady).to.have.length(1);
188
- });
189
-
190
- it('5. ошибка PG при основном чтении → fail-closed', async () => {
191
- const adapter = require('../src/runtime/persistence-port').persistence();
192
- adapter.sceneAssets.getAsset = async () => { throw new Error('pg down'); };
193
- calls.nullRow = { build_id: null, scene_content_version: 5, scene_audio_config_version: 5 };
194
-
195
- const result = await runGate();
196
-
197
- expect(result.completed).to.be.false;
198
- expect(calls.markReady).to.have.length(0);
199
- });
200
-
201
- it('6. ошибка PG при fallback-чтении → fail-closed', async () => {
202
- calls.buildRow = null;
203
- calls.nullRowError = new Error('pg down (null-build read)');
204
-
205
- const result = await runGate();
206
-
207
- expect(result.completed).to.be.false;
208
- expect(result.reason).to.equal('stale');
209
- expect(calls.markReady).to.have.length(0);
210
- });
211
- });
@@ -1,60 +0,0 @@
1
- // ======================================================
2
- // ORCHESTRATION PACKAGE TEST BINDINGS
3
- // ======================================================
4
- // The package self-containedness fixture: wires ONLY what package-local
5
- // (pure-policy) tests need and what the package itself cannot own:
6
- //
7
- // 1. @animastor/generation GenerationConfig port — the media-registry
8
- // self-bootstrap (default-registrations) reads the canonical config
9
- // slices through this port. In the host it is bound by the host adapter
10
- // (backend/src/config/generation-config-adapter.js) from runtime-config.
11
- // Package tests have no host, so this fixture binds the SAME canonical
12
- // slice VALUES frozen here (the host S2-G drift guards still compare
13
- // the registry against runtime-config directly, so any divergence of
14
- // these literals fails there first).
15
- //
16
- // 2. @animastor/orchestration host-bindings — package files fail fast at
17
- // call time unless the composition root wires the host surfaces. Tests
18
- // that exercise only pure-policy modules (no host touch) need nothing;
19
- // tests that stub host modules install their stubs directly here via
20
- // `bindHostModules` (same discipline as the host composition root).
21
- //
22
- // Loaded for EVERY package mocha run via `npm test` (see package.json).
23
- //
24
- // Docs: docs/architecture/generation-module-extraction-reconnaissance.md §32.30
25
- // ======================================================
26
-
27
- // 1) GenerationConfig port (canonical host slice values, frozen)
28
- const { setGenerationConfig } = require('@animastor/generation').ports.generationConfig;
29
-
30
- setGenerationConfig({
31
- leaseTtlS: {
32
- AUDIO: 1860, // = ceil(STALL_FAILSAFE_MS/1000) + 60 (GPU_TIMEOUT_MS=600_000)
33
- IMAGE: 1200, // = 20 * 60
34
- VIDEO: 1800, // = 30 * 60
35
- },
36
- quotas: {
37
- MAX_ACTIVE_AUDIO: 8,
38
- MAX_ACTIVE_IMAGE: 4,
39
- MAX_ACTIVE_VIDEO: 2,
40
- },
41
- stuckThresholds: {
42
- AUDIO_GENERATING: 15,
43
- AUDIO_PENDING: 15,
44
- IMAGE_GENERATING: 30,
45
- IMAGE_PENDING: 30,
46
- VIDEO_GENERATING: 60,
47
- VIDEO_PENDING: 60,
48
- },
49
- });
50
-
51
- // 2) host-bindings default: a fail-fast stub set — any host touch that a
52
- // package test does not explicitly re-wire must throw, never silently no-op
53
- // (matches the production unwired-seam semantics).
54
- const { bindHostModules } = require('../src/host/host-bindings');
55
-
56
- bindHostModules({
57
- journal: () => {
58
- throw new Error('[ORCH-TEST-BINDINGS] host journal not wired — wire it in the test that asserts journal behavior');
59
- },
60
- });
File without changes