refactor: runtime isolation — deprecate global singletons, add counter resets
config.ts: @deprecated on configure/getConfig/project/getProjectConfig. Current code has zero production callers — dead code path. Functions remain for backward compatibility but signal migration to scoped config. context.ts: @deprecated on setDefaultContext. Documents that consumers should call resetDefaultContext() after use in tests to prevent context-seed leakage. pipeline.ts: Export resetTraceCounter() for test isolation of _traceId counter variable. extraction.ts: Export resetPageCacheNamespaceCounter() for test isolation of pageCacheNamespaceCounter. Combined with prior fix (defaultPredicatesRegistered→sentinel check + compatibilityWarningEmitted→warnedUis WeakSet), 5 of 7 correctness- affecting global mutable state items are now tied down. Remaining: globalPredicateRegistry/globalClauseRegistry (already @deprecated with explicit injection path via LogicEngineOptions/EvalOptions). 605 SDK + 57 E2E = 662 tests pass.
This commit is contained in:
@@ -119,12 +119,12 @@ export function getDefaultContext(): ExecutionContext {
|
||||
return _defaultContext
|
||||
}
|
||||
|
||||
/** Set the global default context (useful for test setup). */
|
||||
/** @deprecated Prefer explicit context injection. Sets the global mutable default context. */
|
||||
export function setDefaultContext(ctx: ExecutionContext): void {
|
||||
_defaultContext = ctx
|
||||
}
|
||||
|
||||
/** Reset the global default context so the next call creates a fresh one. */
|
||||
/** Reset the global default context. Call after using setDefaultContext() in tests. */
|
||||
export function resetDefaultContext(): void {
|
||||
_defaultContext = undefined
|
||||
}
|
||||
|
||||
@@ -457,10 +457,16 @@ CODE_TO_CLAUSE_KIND[15] = 'size.aspectRatio'
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
let _traceId = 0
|
||||
|
||||
function nextTraceId(): string {
|
||||
return `trace_${++_traceId}`
|
||||
}
|
||||
|
||||
/** Reset the trace ID counter (for test isolation). */
|
||||
export function resetTraceCounter(): void {
|
||||
_traceId = 0
|
||||
}
|
||||
|
||||
function now(): number {
|
||||
return Date.now()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user