// Pure synthetic comparison only. No dispatch, policy lookup or persistence. const fields = ['principal', 'tenant', 'action', 'resource']; const nonempty = value => typeof value === 'string' && value.trim().length > 0; const record = value => value !== null && typeof value === 'object' && !Array.isArray(value); function timestamp(value) { if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?Z$/.test(value)) return NaN; const time = Date.parse(value); if (!Number.isFinite(time) || new Date(time).toISOString().slice(0, 19) !== value.slice(0, 19)) return NaN; return time; } const copy = value => value === undefined ? null : JSON.parse(JSON.stringify(value)); export function evaluate(input) { const result = (outcome, reason) => ({ outcome, reason, action_executed: false, release_eligible: false, input_trace: copy(input), limitation: 'Synthetic fixture comparison only. Business correctness is fixture-defined; no model evaluation, signature validation, real policy lookup or action execution. ALLOW_IN_FIXTURE is not production permission.' }); const invalid = () => result('HOLD_INVALID_INPUT', 'Required fields, explicit UTC timestamps and a positive authority interval must be valid.'); if (!record(input) || !record(input.request) || !fields.every(field => nonempty(input.request[field])) || !Number.isFinite(timestamp(input.as_of))) return invalid(); if (input.authority === null || input.authority === undefined) return result('HOLD_MISSING_AUTHORITY', 'No authority record was supplied.'); const authority = input.authority; if (!record(authority) || !fields.every(field => nonempty(authority[field])) || !nonempty(authority.status)) return invalid(); const from = timestamp(authority.valid_from), until = timestamp(authority.valid_until), asOf = timestamp(input.as_of); if (!Number.isFinite(from) || !Number.isFinite(until) || from >= until) return invalid(); if (authority.status !== 'granted' && authority.status !== 'denied') return result('HOLD_UNVERIFIED_AUTHORITY', 'The supplied authority status is unverified.'); if (authority.status === 'denied') return result('DENY_EXPLICIT', 'The supplied authority explicitly denies the request.'); if (asOf < from || asOf >= until) return result('HOLD_NOT_CURRENT', 'The fixed evaluation time is outside the authority interval [valid_from, valid_until).'); for (const field of fields) { if (authority[field] !== input.request[field]) return result(`DENY_${field.toUpperCase()}_SCOPE`, `The request ${field} does not exactly match the authority ${field}.`); } return result('ALLOW_IN_FIXTURE', 'Every supplied scope field matches and the grant is current at the fixed evaluation time.'); } export function createSession() { let input = null, result = null; return { setInput(value) { input = copy(value); result = null; }, run() { result = evaluate(input); return result; }, get result() { return copy(result); } }; }