import { describe, it, expect } from 'vitest';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';

/**
 * Online/offline parity guard: the Friendship V2 weekly tick must be invoked
 * from BOTH loops (this is the project's #1 recurring bug class — a fix landing
 * in one loop only). Source-level check, mirroring how the loops are mirrored.
 */
describe('friendship tick wiring', () => {
  const read = (p: string) => readFileSync(join(process.cwd(), p), 'utf8');

  it('PlayerSession (online) calls processWeeklyFriendshipTick', () => {
    expect(read('src/game/PlayerSession.ts')).toContain('processWeeklyFriendshipTick(this.player)');
  });

  it('GameEngine (offline) calls processWeeklyFriendshipTick', () => {
    expect(read('src/game/engine/GameEngine.ts')).toContain('processWeeklyFriendshipTick(player)');
  });

  it('T9 family beats no longer cover friend tags (no double-beating)', () => {
    const src = read('src/events/relationships/randomEvents.ts');
    const tagBlock = src.slice(src.indexOf('const FRIEND_TAGS'), src.indexOf('const FRIEND_TAGS') + 300);
    // Bare "'friend'" (no trailing comma) also catches 'friend' re-added as the
    // LAST set element. Safe from substring false-positives: the quoted check
    // only matches the exact tag literal, and the multi-word friend tags
    // ('best friend', etc.) whose text contains "friend" are gone from the
    // family-only set anyway.
    expect(tagBlock).not.toContain("'friend'");
    expect(tagBlock).toContain("'family'");
  });
});
