fix: rebind imported experiments to active inputs

This commit is contained in:
2026-08-29 08:35:39 +09:00
parent 62971e07ec
commit 447f77dfa7
7 changed files with 130 additions and 47 deletions
+25 -11
View File
@@ -1568,16 +1568,30 @@ async function importDocument(kind, input) {
try {
const value = await readJsonFile(file);
if (generation !== state.importGenerations[kind]) return;
let importedExperimentReferences = null;
let issues;
if (kind === "array") {
issues = await validateArrayDefinition(value);
} else if (kind === "scene") {
issues = await validateScene(value);
} else {
// An Experiment is a useful editable document even before its referenced
// Scene or Array has been loaded. Validate its own contract here, then let
// validateCurrent() keep Run disabled until the document IDs line up.
// Validate the imported document independently before changing any
// references. Then bind it to the open workspace and run the relationship
// checks as well, so import convenience does not weaken the contract.
issues = await validateExperiment(value);
if (generation !== state.importGenerations[kind]) return;
if (issues.length === 0) {
importedExperimentReferences = {
sceneId: value.sceneId,
arrayId: value.arrayId,
};
value.sceneId = state.scene.id;
value.arrayId = state.arrayDefinition.id;
issues = await validateExperiment(value, {
arrayDefinition: state.arrayDefinition,
scene: state.scene,
});
}
}
if (generation !== state.importGenerations[kind]) return;
if (issues.length > 0) throw new Error(issues.slice(0, 4).map(formatIssue).join(" · "));
@@ -1606,14 +1620,14 @@ async function importDocument(kind, input) {
: kind === "experiment"
? ` · 분석 대역 ${state.experiment.frequencyBands.length}개`
: "";
const pendingReferences = kind === "experiment"
? [
value.sceneId !== state.scene?.id ? `Scene ${value.sceneId}` : null,
value.arrayId !== state.arrayDefinition?.id ? `Array ${value.arrayId}` : null,
].filter(Boolean)
: [];
const referenceStatus = pendingReferences.length > 0
? ` · ${pendingReferences.join(" · ")} 연결 대기`
const referencesChanged = kind === "experiment" && (
importedExperimentReferences?.sceneId !== state.scene.id ||
importedExperimentReferences?.arrayId !== state.arrayDefinition.id
);
const referenceStatus = kind === "experiment"
? referencesChanged
? ` · 현재 Scene ${state.scene.id} · Array ${state.arrayDefinition.id}로 재연결`
: " · 현재 Scene · Array 연결 확인"
: "";
setRunStatus(`${file.name} ${kind} 문서를 불러왔습니다.${bandStatus}${referenceStatus}`);
} catch (error) {