(
hfId: string,
targetPath: string,
timingUpdate: { start?: number; duration?: number; trackIndex?: number },
sdkSession: Composition | null | undefined,
deps: CutoverDeps,
options?: CutoverOptions,
)
| 156 | } |
| 157 | |
| 158 | export async function sdkTimingPersist( |
| 159 | hfId: string, |
| 160 | targetPath: string, |
| 161 | timingUpdate: { start?: number; duration?: number; trackIndex?: number }, |
| 162 | sdkSession: Composition | null | undefined, |
| 163 | deps: CutoverDeps, |
| 164 | options?: CutoverOptions, |
| 165 | ): Promise<boolean> { |
| 166 | // Resolver tripwire — runs BEFORE the cutover gate (decoupled): records when |
| 167 | // the SDK can't resolve a target the server timing path is addressing. |
| 168 | const timingSrc = deps.readProjectFile; |
| 169 | void recordResolverParity( |
| 170 | sdkSession, |
| 171 | hfId, |
| 172 | "setTiming", |
| 173 | timingSrc ? () => timingSrc(targetPath) : undefined, |
| 174 | ); |
| 175 | // Dark-launch gate: without this, timing cutover runs whenever an SDK session |
| 176 | // exists (it always does, for shadow/selection) — flipping the flag OFF would |
| 177 | // NOT disable it. Gate here so flag-off routes back to the legacy server path. |
| 178 | if (!STUDIO_SDK_CUTOVER_ENABLED) return false; |
| 179 | if (!sdkSession || !sdkSession.getElement(hfId)) return false; |
| 180 | if (wrongCompositionFile(deps, targetPath)) return false; |
| 181 | try { |
| 182 | const serializedBefore = sdkSession.serialize(); |
| 183 | sdkSession.batch(() => sdkSession.setTiming(hfId, timingUpdate)); |
| 184 | const after = sdkSession.serialize(); |
| 185 | if (after === serializedBefore) return false; |
| 186 | // Undo baseline = exact on-disk bytes (matching the style/delete paths), so |
| 187 | // undoing a timing edit restores the file verbatim instead of a normalized |
| 188 | // full-DOM re-emit. Falls back to serializedBefore when no reader is wired. |
| 189 | const undoBefore = await captureOnDiskBefore(deps, targetPath, serializedBefore); |
| 190 | await persistSdkSerialize(after, targetPath, undoBefore, deps, options); |
| 191 | trackStudioEvent("sdk_cutover_success", { hfId, opCount: 1 }); |
| 192 | return true; |
| 193 | } catch (err) { |
| 194 | trackStudioEvent("sdk_cutover_fallback", { hfId, error: String(err) }); |
| 195 | return false; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | type SdkGsapTweenOp = |
| 200 | | { kind: "add"; target: string; spec: GsapTweenSpec } |
no test coverage detected