fix(monsters): finish deleting experienceReward, column included
Design ruling R7 abolishes XP as a concept and says the column goes with it, but no task in the plan actually dropped it -- the plan only dropped characters.experience and combat_rewards.experience_granted. Task 9 removed experienceReward from the seed literals, leaving monster_definitions.experience_reward as a NOT NULL column with no default that nothing supplies. The first monster insert against a real database would have failed on a constraint violation. No suite here could have caught it: none of them connect to Postgres. Drops the column in the slice migration (which has never been run, so amending it in place is correct rather than stacking a second one), removes the entity field, and clears the three test fixtures that still set it. silver_min/silver_max deliberately stay -- spec 15 keeps a direct currency drop available as a lore-valid exception, and XP has no such carve-out. Also retargets the seed idempotency test off renown: 1, which is the seed's own default and so could not distinguish "preserved" from "reset to default". NOTE ON SCOPE: this commit also absorbs a Prettier reformatting pass that was already sitting uncommitted in the working tree, which is why it touches ~59 files. That churn is purely cosmetic line-rewrapping -- verified by inspection, and the suite is green at 267/267 with the build at exactly the 3 expected errors owned by Tasks 10 and 11. The repo is not Prettier-clean at baseline (119 files still flagged), so this was a partial run by an earlier step, not a deliberate repo-wide format. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,9 +12,13 @@ import { Character } from '../../characters/entities/character.entity';
|
||||
import { ReputationFaction } from './reputation-faction.entity';
|
||||
|
||||
@Entity({ name: 'character_reputation' })
|
||||
@Index('IDX_character_reputation_character_faction', ['characterId', 'factionId'], {
|
||||
unique: true,
|
||||
})
|
||||
@Index(
|
||||
'IDX_character_reputation_character_faction',
|
||||
['characterId', 'factionId'],
|
||||
{
|
||||
unique: true,
|
||||
},
|
||||
)
|
||||
export class CharacterReputation {
|
||||
@PrimaryGeneratedColumn('uuid', { name: 'id' })
|
||||
id!: string;
|
||||
|
||||
@@ -7,7 +7,11 @@ export interface ReputationRankInfo {
|
||||
|
||||
// Verbatim thresholds from spec §10, German labels for the German-language UI.
|
||||
// Sorted descending: the first entry whose threshold <= reputation wins.
|
||||
const REPUTATION_RANKS: ReadonlyArray<{ threshold: number; key: string; label: string }> = [
|
||||
const REPUTATION_RANKS: ReadonlyArray<{
|
||||
threshold: number;
|
||||
key: string;
|
||||
label: string;
|
||||
}> = [
|
||||
{ threshold: 1200, key: 'ESTEEMED', label: 'Geachtet' },
|
||||
{ threshold: 800, key: 'TRUSTED', label: 'Vertraut' },
|
||||
{ threshold: 500, key: 'RECOGNIZED', label: 'Anerkannt' },
|
||||
@@ -17,7 +21,9 @@ const REPUTATION_RANKS: ReadonlyArray<{ threshold: number; key: string; label: s
|
||||
];
|
||||
|
||||
export function resolveReputationRank(reputation: number): ReputationRankInfo {
|
||||
const index = REPUTATION_RANKS.findIndex((rank) => reputation >= rank.threshold);
|
||||
const index = REPUTATION_RANKS.findIndex(
|
||||
(rank) => reputation >= rank.threshold,
|
||||
);
|
||||
const rank = REPUTATION_RANKS[index];
|
||||
const nextRank = index > 0 ? REPUTATION_RANKS[index - 1] : null;
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@ describe('ReputationController', () => {
|
||||
getCharacterReputation.mockReset();
|
||||
const module = await Test.createTestingModule({
|
||||
controllers: [ReputationController],
|
||||
providers: [{ provide: ReputationService, useValue: { getCharacterReputation } }],
|
||||
providers: [
|
||||
{ provide: ReputationService, useValue: { getCharacterReputation } },
|
||||
],
|
||||
}).compile();
|
||||
|
||||
app = module.createNestApplication<App>();
|
||||
@@ -40,7 +42,9 @@ describe('ReputationController', () => {
|
||||
];
|
||||
getCharacterReputation.mockResolvedValue(entries);
|
||||
|
||||
const response = await request(app.getHttpServer()).get('/api/reputation').expect(200);
|
||||
const response = await request(app.getHttpServer())
|
||||
.get('/api/reputation')
|
||||
.expect(200);
|
||||
|
||||
expect(getCharacterReputation).toHaveBeenCalledWith(DEMO_CHARACTER_ID);
|
||||
expect(response.body).toEqual(entries);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { DEMO_CHARACTER_ID } from '../demo/demo-character.constants';
|
||||
import { CharacterReputationDto, ReputationService } from './reputation.service';
|
||||
import {
|
||||
CharacterReputationDto,
|
||||
ReputationService,
|
||||
} from './reputation.service';
|
||||
|
||||
@Controller('reputation')
|
||||
export class ReputationController {
|
||||
|
||||
@@ -22,20 +22,29 @@ class FakeRepository<T extends { id: string }> {
|
||||
private readonly inTransaction: boolean,
|
||||
) {}
|
||||
|
||||
findOne(options: { where: Partial<T>; lock?: { mode: string } }): Promise<T | null> {
|
||||
findOne(options: {
|
||||
where: Partial<T>;
|
||||
lock?: { mode: string };
|
||||
}): Promise<T | null> {
|
||||
if (options.lock && !this.inTransaction) {
|
||||
throw new Error('Pessimistic locks require a transaction');
|
||||
}
|
||||
return Promise.resolve(this.rows.find((row) => this.matches(row, options.where)) ?? null);
|
||||
return Promise.resolve(
|
||||
this.rows.find((row) => this.matches(row, options.where)) ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
findOneBy(where: Partial<T>): Promise<T | null> {
|
||||
return Promise.resolve(this.rows.find((row) => this.matches(row, where)) ?? null);
|
||||
return Promise.resolve(
|
||||
this.rows.find((row) => this.matches(row, where)) ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
find(options: { where?: Partial<T> } = {}): Promise<T[]> {
|
||||
return Promise.resolve(
|
||||
options.where ? this.rows.filter((row) => this.matches(row, options.where!)) : [...this.rows],
|
||||
options.where
|
||||
? this.rows.filter((row) => this.matches(row, options.where!))
|
||||
: [...this.rows],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -57,7 +66,9 @@ class FakeRepository<T extends { id: string }> {
|
||||
}
|
||||
|
||||
private matches(row: T, where: Partial<T>): boolean {
|
||||
return Object.entries(where).every(([key, value]) => row[key as keyof T] === value);
|
||||
return Object.entries(where).every(
|
||||
([key, value]) => row[key as keyof T] === value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,19 +79,37 @@ class FakeDataSource {
|
||||
return this.repoFor(target, false);
|
||||
}
|
||||
|
||||
async transaction<T>(work: (manager: EntityManager) => Promise<T>): Promise<T> {
|
||||
async transaction<T>(
|
||||
work: (manager: EntityManager) => Promise<T>,
|
||||
): Promise<T> {
|
||||
return work({
|
||||
getRepository: <U extends { id: string }>(target: EntityTarget<U>) => this.repoFor(target, true),
|
||||
getRepository: <U extends { id: string }>(target: EntityTarget<U>) =>
|
||||
this.repoFor(target, true),
|
||||
} as unknown as EntityManager);
|
||||
}
|
||||
|
||||
private repoFor<T extends { id: string }>(target: EntityTarget<T>, inTransaction: boolean) {
|
||||
private repoFor<T extends { id: string }>(
|
||||
target: EntityTarget<T>,
|
||||
inTransaction: boolean,
|
||||
) {
|
||||
if (target === Character)
|
||||
return new FakeRepository(this.state.characters, 'character', inTransaction) as never;
|
||||
return new FakeRepository(
|
||||
this.state.characters,
|
||||
'character',
|
||||
inTransaction,
|
||||
) as never;
|
||||
if (target === ReputationFaction)
|
||||
return new FakeRepository(this.state.factions, 'faction', inTransaction) as never;
|
||||
return new FakeRepository(
|
||||
this.state.factions,
|
||||
'faction',
|
||||
inTransaction,
|
||||
) as never;
|
||||
if (target === CharacterReputation)
|
||||
return new FakeRepository(this.state.characterReputation, 'char-rep', inTransaction) as never;
|
||||
return new FakeRepository(
|
||||
this.state.characterReputation,
|
||||
'char-rep',
|
||||
inTransaction,
|
||||
) as never;
|
||||
throw new Error('Unsupported repository');
|
||||
}
|
||||
}
|
||||
@@ -89,7 +118,9 @@ function character(overrides: Partial<Character> = {}): Character {
|
||||
return { id: CHARACTER_ID, ...overrides } as Character;
|
||||
}
|
||||
|
||||
function faction(overrides: Partial<ReputationFaction> = {}): ReputationFaction {
|
||||
function faction(
|
||||
overrides: Partial<ReputationFaction> = {},
|
||||
): ReputationFaction {
|
||||
return {
|
||||
id: FACTION_ID,
|
||||
key: 'border-guard',
|
||||
@@ -102,15 +133,26 @@ function faction(overrides: Partial<ReputationFaction> = {}): ReputationFaction
|
||||
}
|
||||
|
||||
function createState(overrides: Partial<State> = {}): State {
|
||||
return { characters: [character()], factions: [faction()], characterReputation: [], ...overrides };
|
||||
return {
|
||||
characters: [character()],
|
||||
factions: [faction()],
|
||||
characterReputation: [],
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function createService(state: State) {
|
||||
const dataSource = new FakeDataSource(state);
|
||||
return { service: new ReputationService(dataSource as unknown as DataSource), state };
|
||||
return {
|
||||
service: new ReputationService(dataSource as unknown as DataSource),
|
||||
state,
|
||||
};
|
||||
}
|
||||
|
||||
async function expectReputationDomainError(promise: Promise<unknown>, code: string): Promise<void> {
|
||||
async function expectReputationDomainError(
|
||||
promise: Promise<unknown>,
|
||||
code: string,
|
||||
): Promise<void> {
|
||||
let error: unknown;
|
||||
try {
|
||||
await promise;
|
||||
@@ -154,7 +196,11 @@ describe('ReputationService', () => {
|
||||
it('creates a reputation row starting from 0 on the first grant', async () => {
|
||||
const { service, state } = createService(createState());
|
||||
|
||||
const result = await service.grantReputation(CHARACTER_ID, 'border-guard', 40);
|
||||
const result = await service.grantReputation(
|
||||
CHARACTER_ID,
|
||||
'border-guard',
|
||||
40,
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
factionKey: 'border-guard',
|
||||
@@ -171,12 +217,21 @@ describe('ReputationService', () => {
|
||||
it('accumulates onto an existing reputation row', async () => {
|
||||
const state = createState({
|
||||
characterReputation: [
|
||||
{ id: 'existing', characterId: CHARACTER_ID, factionId: FACTION_ID, reputation: 90 } as CharacterReputation,
|
||||
{
|
||||
id: 'existing',
|
||||
characterId: CHARACTER_ID,
|
||||
factionId: FACTION_ID,
|
||||
reputation: 90,
|
||||
} as CharacterReputation,
|
||||
],
|
||||
});
|
||||
const { service } = createService(state);
|
||||
|
||||
const result = await service.grantReputation(CHARACTER_ID, 'border-guard', 20);
|
||||
const result = await service.grantReputation(
|
||||
CHARACTER_ID,
|
||||
'border-guard',
|
||||
20,
|
||||
);
|
||||
|
||||
expect(result.previousReputation).toBe(90);
|
||||
expect(result.newReputation).toBe(110);
|
||||
@@ -185,12 +240,21 @@ describe('ReputationService', () => {
|
||||
it('reports rankChanged when a grant crosses a threshold', async () => {
|
||||
const state = createState({
|
||||
characterReputation: [
|
||||
{ id: 'existing', characterId: CHARACTER_ID, factionId: FACTION_ID, reputation: 90 } as CharacterReputation,
|
||||
{
|
||||
id: 'existing',
|
||||
characterId: CHARACTER_ID,
|
||||
factionId: FACTION_ID,
|
||||
reputation: 90,
|
||||
} as CharacterReputation,
|
||||
],
|
||||
});
|
||||
const { service } = createService(state);
|
||||
|
||||
const result = await service.grantReputation(CHARACTER_ID, 'border-guard', 20);
|
||||
const result = await service.grantReputation(
|
||||
CHARACTER_ID,
|
||||
'border-guard',
|
||||
20,
|
||||
);
|
||||
|
||||
expect(result.previousRank).toBe('STRANGER');
|
||||
expect(result.newRank).toBe('TOLERATED');
|
||||
@@ -200,12 +264,21 @@ describe('ReputationService', () => {
|
||||
it('reports rankChanged: false when a grant stays within the same rank', async () => {
|
||||
const state = createState({
|
||||
characterReputation: [
|
||||
{ id: 'existing', characterId: CHARACTER_ID, factionId: FACTION_ID, reputation: 120 } as CharacterReputation,
|
||||
{
|
||||
id: 'existing',
|
||||
characterId: CHARACTER_ID,
|
||||
factionId: FACTION_ID,
|
||||
reputation: 120,
|
||||
} as CharacterReputation,
|
||||
],
|
||||
});
|
||||
const { service } = createService(state);
|
||||
|
||||
const result = await service.grantReputation(CHARACTER_ID, 'border-guard', 10);
|
||||
const result = await service.grantReputation(
|
||||
CHARACTER_ID,
|
||||
'border-guard',
|
||||
10,
|
||||
);
|
||||
|
||||
expect(result.rankChanged).toBe(false);
|
||||
});
|
||||
|
||||
@@ -3,7 +3,10 @@ import { DataSource, EntityManager } from 'typeorm';
|
||||
import { Character } from '../characters/entities/character.entity';
|
||||
import { CharacterReputation } from './entities/character-reputation.entity';
|
||||
import { ReputationFaction } from './entities/reputation-faction.entity';
|
||||
import { characterNotFound, reputationFactionNotFound } from './reputation.errors';
|
||||
import {
|
||||
characterNotFound,
|
||||
reputationFactionNotFound,
|
||||
} from './reputation.errors';
|
||||
import { resolveReputationRank } from './reputation-rank';
|
||||
|
||||
export interface ReputationGrantResult {
|
||||
@@ -37,7 +40,9 @@ export class ReputationService {
|
||||
amount: number,
|
||||
manager?: EntityManager,
|
||||
): Promise<ReputationGrantResult> {
|
||||
const run = async (txManager: EntityManager): Promise<ReputationGrantResult> => {
|
||||
const run = async (
|
||||
txManager: EntityManager,
|
||||
): Promise<ReputationGrantResult> => {
|
||||
const characters = txManager.getRepository(Character);
|
||||
const factions = txManager.getRepository(ReputationFaction);
|
||||
const reputations = txManager.getRepository(CharacterReputation);
|
||||
@@ -74,7 +79,11 @@ export class ReputationService {
|
||||
await reputations.save(existing);
|
||||
} else {
|
||||
await reputations.save(
|
||||
reputations.create({ characterId, factionId: faction.id, reputation: newReputation }),
|
||||
reputations.create({
|
||||
characterId,
|
||||
factionId: faction.id,
|
||||
reputation: newReputation,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -99,10 +108,16 @@ export class ReputationService {
|
||||
* never interacted with reads as 0 Reputation / Stranger (spec §36,
|
||||
* design R10), not as an absent entry.
|
||||
*/
|
||||
async getCharacterReputation(characterId: string): Promise<CharacterReputationDto[]> {
|
||||
async getCharacterReputation(
|
||||
characterId: string,
|
||||
): Promise<CharacterReputationDto[]> {
|
||||
const scope: RepositoryScope = this.dataSource;
|
||||
const factions = await scope.getRepository(ReputationFaction).find({ where: { enabled: true } });
|
||||
const reputations = await scope.getRepository(CharacterReputation).find({ where: { characterId } });
|
||||
const factions = await scope
|
||||
.getRepository(ReputationFaction)
|
||||
.find({ where: { enabled: true } });
|
||||
const reputations = await scope
|
||||
.getRepository(CharacterReputation)
|
||||
.find({ where: { characterId } });
|
||||
|
||||
return factions.map((faction) => {
|
||||
const existing = reputations.find((row) => row.factionId === faction.id);
|
||||
|
||||
Reference in New Issue
Block a user