fix: stabilize match3d demo discovery

This commit is contained in:
2026-05-26 00:13:08 +08:00
parent 5d3e2ac111
commit f79a6ea81e
123 changed files with 1778 additions and 233 deletions

View File

@@ -447,7 +447,10 @@ function settleMatchedTrayItems(
};
}
export function startLocalMatch3DRun(clearCount = 12): Match3DRunSnapshot {
export function startLocalMatch3DRun(
clearCount = 12,
profileId = 'local-match3d-profile',
): Match3DRunSnapshot {
const normalizedClearCount =
normalizeLocalMatch3DRuntimeClearCount(clearCount);
const selectedSeeds = selectVisualSeeds(normalizedClearCount);
@@ -467,7 +470,7 @@ export function startLocalMatch3DRun(clearCount = 12): Match3DRunSnapshot {
const nowMs = Date.now();
return {
runId: `local-match3d-run-${nowMs}`,
profileId: 'local-match3d-profile',
profileId,
status: 'Running',
snapshotVersion: 1,
startedAtMs: nowMs,

View File

@@ -95,7 +95,7 @@ test('local Match3D runtime adapter exposes the same runtime seam as the server
const started = await adapter.startRun('ignored-local-profile');
const clickableItem = started.run.items.find((item) => item.clickable);
expect(started.run.profileId).toBe('local-match3d-profile');
expect(started.run.profileId).toBe('ignored-local-profile');
expect(clickableItem).toBeTruthy();
const clickResult = await adapter.clickItem(started.run.runId, {
@@ -117,6 +117,15 @@ test('local Match3D runtime adapter exposes the same runtime seam as the server
expect(stopped.run.status).toBe('Stopped');
});
test('local Match3D runtime adapter keeps the requested profile id on restart', async () => {
const adapter = createLocalMatch3DRuntimeAdapter({ clearCount: 1 });
const started = await adapter.startRun('match3d-demo-20260525');
const restarted = await adapter.restartRun(started.run.runId);
expect(started.run.profileId).toBe('match3d-demo-20260525');
expect(restarted.run.profileId).toBe('match3d-demo-20260525');
});
test('local Match3D runtime adapter keeps authority run local to the adapter', async () => {
const adapter = createLocalMatch3DRuntimeAdapter({ initialRun: startLocalMatch3DRun(1) });
const first = await adapter.getRun('unused-run-id');

View File

@@ -36,6 +36,7 @@ export type Match3DRuntimeAdapter = {
export type LocalMatch3DRuntimeAdapterOptions = {
clearCount?: number;
profileId?: string;
initialRun?: Match3DRunResponse['run'];
};
@@ -74,11 +75,16 @@ export function createServerMatch3DRuntimeAdapter(
export function createLocalMatch3DRuntimeAdapter(
options: LocalMatch3DRuntimeAdapterOptions = {},
): Match3DRuntimeAdapter {
let authorityRun = options.initialRun ?? startLocalMatch3DRun(options.clearCount);
let authorityRun =
options.initialRun ??
startLocalMatch3DRun(options.clearCount, options.profileId);
return {
async startRun() {
authorityRun = startLocalMatch3DRun(options.clearCount);
async startRun(profileId) {
authorityRun = startLocalMatch3DRun(
options.clearCount,
profileId || options.profileId,
);
return { run: authorityRun };
},
async getRun() {
@@ -91,7 +97,10 @@ export function createLocalMatch3DRuntimeAdapter(
return result;
},
async restartRun() {
authorityRun = startLocalMatch3DRun(options.clearCount);
authorityRun = startLocalMatch3DRun(
options.clearCount,
authorityRun.profileId || options.profileId,
);
return { run: authorityRun };
},
async stopRun() {