'use strict'; const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const test = require('node:test'); const { createConsoleProfileService } = require('../../src/services/console-profile-service'); class Settings { constructor(values = {}) { this.values = values; } get(key, fallback) { return Object.prototype.hasOwnProperty.call(this.values, key) ? this.values[key] : fallback; } set(key, value) { this.values[key] = value; } } const secrets = { has: () => false, get: () => '', set() {} }; test('identity evidence is bounded, masked and exposed read-only without a mutation contract', () => { const settings = new Settings({ 'console.identityEvidence': { localUsername: ' Local\u0000User ', accountId: 'abcdef1234567890', psnOnlineId: 'Player_One', linked: true, source: 'sentinel', observedAt: 1_800_000_000_000 } }); const service = createConsoleProfileService({ settings, secrets, uuid: () => 'profile-a' }); const identity = service.identity(); assert.equal(identity.local.username, 'Local User'); assert.equal(identity.local.accountIdMasked, '************7890'); assert.equal(identity.linkedPsn.onlineId, 'Player_One'); assert.equal(identity.readOnly, true); assert.equal(identity.mutationAvailable, false); assert.match(identity.officialOnlineIdGuidance, /^https:\/\/www\.playstation\.com\/support\//); service.save({ id: 'profile-a', identity: { psnOnlineId: 'InjectedName', linked: true } }); assert.equal(service.identity().linkedPsn.onlineId, 'Player_One'); }); test('invalid identity fields fail closed instead of leaking unsafe values', () => { const settings = new Settings({ 'console.identityEvidence': { localUsername: '