fix(ci): repair server and shared gates after the place identities change

Push run 46275645144 on dev (f69a4c1a2) was red in these jobs:

- Server types: UserPlacesRepository.create, UserPlaceMergesRepository.create
  and UserPlaceLinksRepository.insert shadowed MikroORM's EntityRepository
  methods with other signatures (TS2416), which also broke defineEntity on the
  three entities (TS2769). They are createOwn, record and insertUses now.
- Server lint: collections.service.ts had grown to 1411 lines against 1410.
  The trip tag lookup of a copy moved into collections.helpers.ts
  (tripTagIdsOf, tagKeyOf); the size baseline is lowered to the 1398 it holds.
- ASTCAP-001/002/005b: the trip chat core had taken in PlacesLibraryMcp,
  PlaceIdentitiesMcp and TripCollectionsMcp, so core and the tours group
  offered 132 tools against 128. They load with the collections group now.
- PLIB-001, PLIB-MCP-001 and the places library e2e: the two entries named
  Museum tie on the name and go by their anchor, which the expected order
  hard coded the other way. The fixture orders every tie by its anchors.
- ENT-003 and CLASSFIELD-002: the five new entities and their 18 NOT NULL
  columns without a default are counted.
- Shared tests: collections.ratingBadge was missing in 26 locales; each has
  its translation now.
This commit is contained in:
Maurice
2026-11-29 16:14:42 +01:00
parent f69a4c1a24
commit 7a06db393f
38 changed files with 106 additions and 42 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
"src/nest/atlas/atlas.service.ts": 1166,
"src/nest/auth/auth.service.ts": 1115,
"src/nest/budget/budget.service.ts": 1607,
"src/nest/collections/collections.service.ts": 1410,
"src/nest/collections/collections.service.ts": 1398,
"src/nest/doc-sync/doc-sync.service.ts": 1060,
"src/nest/doc-sync/providers/synology-drive.client.ts": 1160,
"src/nest/journey/journey-domain.service.ts": 1659,
@@ -54,7 +54,7 @@ export class UserPlaceLinksRepository extends TrekRepository<UserPlaceLinks> {
}
/** Links uses no own place of the user holds (`detach` first) to `userPlaceId`; answers the new ids. */
async insert(
async insertUses(
userId: number,
userPlaceId: number,
uses: readonly LinkedUse[],
@@ -18,7 +18,7 @@ export class UserPlaceMergesRepository extends TrekRepository<UserPlaceMerges> {
return this.kysely<UserPlaceMergesDB>();
}
async create(userId: number, leadingId: number, mergedId: number, movedLinkIds: string): Promise<number> {
async record(userId: number, leadingId: number, mergedId: number, movedLinkIds: string): Promise<number> {
const row = await this.db()
.insertInto('user_place_merges')
.values({ user_id: userId, leading_id: leadingId, merged_id: mergedId, moved_link_ids: movedLinkIds })
@@ -38,7 +38,7 @@ export class UserPlacesRepository extends TrekRepository<UserPlaces> {
return this.kysely<UserPlacesDB>();
}
async create(userId: number, facts: UserPlaceFacts): Promise<number> {
async createOwn(userId: number, facts: UserPlaceFacts): Promise<number> {
const row = await this.db()
.insertInto('user_places')
.values({ user_id: userId, ...facts })
@@ -396,8 +396,11 @@ const CORE_TOOL_GROUPS: ToolGroups = {
controllers: ['AtlasMcp', 'AtlasGlobeMcp', 'DawarichAtlasMcp'],
},
collections: {
about: 'Collections: saved places across trips, their labels and ratings.',
controllers: ['CollectionsMcp'],
about:
'Collections and all places: saved places across trips, their labels and ratings, every place of the user ' +
'in one library, the places that are one and the same (linking, merging and undoing a merge, duplicates) ' +
'and the lists linked to this trip.',
controllers: ['CollectionsMcp', 'PlacesLibraryMcp', 'PlaceIdentitiesMcp', 'TripCollectionsMcp'],
},
collab: {
about: 'Trip chat: notes, polls, shared links and messages to the people on the trip.',
@@ -168,3 +168,29 @@ export function placeOrderOf(current: number[], requested: number[]): number[] |
if (named.size !== requested.length || requested.some((id) => !held.has(id))) return null;
return [...requested, ...current.filter((id) => !named.has(id))];
}
/** How a trip tag name is compared: trimmed and in lower case. */
export function tagKeyOf(name: string): string {
return name.trim().toLowerCase();
}
/**
* The trip's own tag of each name, in the order of `tags`: the one `known`
* holds, or one `makeTag` makes now (once per name). `known` keeps the new
* ones, so the next place of the same copy reuses them.
*/
export async function tripTagIdsOf(
tags: { name: string; color: string }[],
known: Map<string, number>,
makeTag: (name: string, color: string) => Promise<number>,
): Promise<number[]> {
const missing = new Map(tags.filter((t) => !known.has(tagKeyOf(t.name))).map((t) => [tagKeyOf(t.name), t]));
const made = await Promise.all(
[...missing.entries()].map(async ([key, { name, color }]) => [key, await makeTag(name.trim(), color)] as const),
);
for (const [key, id] of made) known.set(key, id);
return tags.flatMap(({ name }): number[] => {
const id = known.get(tagKeyOf(name));
return id === undefined ? [] : [id];
});
}
@@ -72,7 +72,8 @@ import { NotificationsService } from '../notifications/notifications.service';
import { PlaceImportService, type ExportedCollectionFile } from '../place-import/place-import.service';
import { UnitOfWork } from '../database/unit-of-work';
import {
filePlaceOf, groupByPid, listingWriteOf, parseLinks, placeOrderOf, serializeLinks, tripDedupSet, tripPlaceFields,
filePlaceOf, groupByPid, listingWriteOf, parseLinks, placeOrderOf, serializeLinks, tagKeyOf, tripDedupSet, tripPlaceFields,
tripTagIdsOf,
} from './collections.helpers';
// Errors: a DomainError carrying a status; TrekExceptionFilter maps it to that code with an `{ error }` body.
@@ -1075,7 +1076,7 @@ export class CollectionsService {
const skipped: { id: number; name: string }[] = [];
// The whole copy is one logical write — atomic since the post-fold quirk pass.
await this.uow.transactional(async () => {
if (carried) for (const t of await this.tags.listByTrip(body.trip_id)) tripTags.set(t.name.trim().toLowerCase(), t.id);
if (carried) for (const t of await this.tags.listByTrip(body.trip_id)) tripTags.set(tagKeyOf(t.name), t.id);
tagsBefore = tripTags.size;
for (const s of sources) {
if (!body.force && isPlaceDuplicate({
@@ -1093,7 +1094,9 @@ export class CollectionsService {
image_url: s.image_url, google_place_id: s.google_place_id, google_ftid: s.google_ftid,
website: s.website, phone: s.phone, osm_id: s.osm_id,
});
await this.tags.insertIgnore(newPlaceId, await this.tripTagIds(body.trip_id, userId, carried?.[s.id] ?? [], tripTags));
const tagIds = await tripTagIdsOf(carried?.[s.id] ?? [], tripTags, async (name, color) =>
(await this.tags.createTag({ user_id: userId, trip_id: body.trip_id, name, color })).id);
await this.tags.insertIgnore(newPlaceId, tagIds);
// Ratings of trip members travel along (#1435); nothing is mirrored back.
const votes = await this.collectionPlaceRatings.listForPlace(s.id);
for (const v of votes) if (tripMemberIds.has(v.user_id)) await this.tripPlaceRatings.insertIgnore(newPlaceId, v.user_id, v.rating);
@@ -1110,19 +1113,6 @@ export class CollectionsService {
return { copied: created.length, skipped, created };
}
/** The trip's own tag of each name: the one it has, or one made now; `known` keeps the new ones for the next place. */
private async tripTagIds(tripId: number, userId: number, tags: { name: string; color: string }[], known: Map<string, number>): Promise<number[]> {
const keyOf = (name: string) => name.trim().toLowerCase();
const missing = [...new Map(tags.filter(t => !known.has(keyOf(t.name))).map(t => [keyOf(t.name), t])).entries()];
const made = await Promise.all(missing.map(async ([key, { name, color }]) =>
[key, (await this.tags.createTag({ user_id: userId, trip_id: tripId, name: name.trim(), color })).id] as const));
for (const [key, id] of made) known.set(key, id);
return tags.flatMap(({ name }): number[] => {
const id = known.get(keyOf(name));
return id === undefined ? [] : [id];
});
}
// -------------------------------------------------------------------------
// Library-wide membership lookup (inspector indicator)
// -------------------------------------------------------------------------
@@ -81,7 +81,7 @@ export class PlaceIdentitiesService {
const target =
request.identity_id === undefined ? { facts: await this.factsOfUse(reach, first) } : { id: request.identity_id };
const identityId = await this.uow.transactional(async () => {
const id = 'id' in target ? target.id : await this.identities.create(user.id, target.facts);
const id = 'id' in target ? target.id : await this.identities.createOwn(user.id, target.facts);
await this.attach(user.id, id, uses, 'user');
await this.identities.touch(user.id, id);
await this.prune(user.id);
@@ -130,7 +130,7 @@ export class PlaceIdentitiesService {
await this.links.moveTo(user.id, moved, leadId);
await this.identities.setMergedInto(user.id, restId, leadId);
await this.identities.touch(user.id, leadId);
const mergeId = await this.merges.create(
const mergeId = await this.merges.record(
user.id,
leadId,
restId,
@@ -197,14 +197,14 @@ export class PlaceIdentitiesService {
linkedBy: 'user' | 'merge',
): Promise<void> {
await this.links.detach(userId, uses);
await this.links.insert(userId, id, uses, linkedBy);
await this.links.insertUses(userId, id, uses, linkedBy);
}
/** The entry's own place, made from its first use when it has none yet. Runs inside the caller's transaction. */
private async materialize(userId: number, rows: EntryRows): Promise<number> {
if (rows.identity) return rows.identity.id;
const first = firstUseOf(rows);
const id = await this.identities.create(userId, {
const id = await this.identities.createOwn(userId, {
name: first.name,
lat: first.lat,
lng: first.lng,
+17 -9
View File
@@ -154,9 +154,10 @@ export async function seedLibrary(orm: FactoryOrm) {
export type LibraryFixture = Awaited<ReturnType<typeof seedLibrary>>;
/**
* The keys of `me`'s entries by name. Café Central's two entries tie on the
* name and then go by their anchor (`id * 4 + kind`, a trip place's kind 1,
* a saved place's 2), so their order follows the ids the seed got.
* The keys of `me`'s entries by name. Two entries of the same name go by their
* anchor (`id * 4 + kind`, a trip place's kind 1, a saved place's 2; a saved
* place grouped with a trip place takes the trip place's), so the order of a
* tie follows the ids the seed got.
*/
export function expectedKeysByName(f: LibraryFixture): string[] {
const { places, saved } = f;
@@ -167,16 +168,23 @@ export function expectedKeysByName(f: LibraryFixture): string[] {
`list:${saved.hiddenCopy.id}`,
`trip:${places.hotel.id}`,
`list:${saved.lunch.id}`,
`list:${saved.namesake.id}`,
`trip:${places.museum.id}`,
...museumTie(f),
`list:${saved.pantheon.id}`,
];
}
/** Two entries of one name, in the order their anchors give. */
function byAnchor(trip: number, list: number): string[] {
const pair = [`list:${list}`, `trip:${trip}`];
return list * 4 + 2 < trip * 4 + 1 ? pair : [...pair].reverse();
}
/** The two entries named Café Central, in the order their anchors give. */
export function cafeTie(f: LibraryFixture): string[] {
const conflicting = f.saved.conflicting.id * 4 + 2;
const cafe = f.places.cafe.id * 4 + 1;
const pair = [`list:${f.saved.conflicting.id}`, `trip:${f.places.cafe.id}`];
return conflicting < cafe ? pair : [...pair].reverse();
return byAnchor(f.places.cafe.id, f.saved.conflicting.id);
}
/** The two entries named Museum (the trip place with its saved copy, and the namesake), as their anchors give. */
export function museumTie(f: LibraryFixture): string[] {
return byAnchor(f.places.museum.id, f.saved.namesake.id);
}
+6 -3
View File
@@ -60,14 +60,17 @@ describe('ALL_ENTITIES', () => {
* + assistant_attachments, the files attached in the trip chat, kept with their conversation
* + mail_ingest_addresses, _prefs, _cursor, _messages and _candidates, the forwarded
* booking mails, the bookings read from them and the switches and addresses behind them
* + trip_addon_overrides, the owner's per-trip on or off for a trip addon)
* + trip_addon_overrides, the owner's per-trip on or off for a trip addon
* + user_places, user_place_links, user_place_merges and user_place_merge_dismissals,
* a user's own place identities, the uses they group, the merges and the dismissed pairs
* + trip_collection_links, the lists a trip links)
* is registered, and no two share a class name (a silent duplicate would
* shadow one of them in `orm.getMetadata()`, exactly the kind of drift
* `entity-schema-parity.test.ts` can't see — it iterates the metadata map,
* which de-duplicates by class name).
*/
it('ENT-003: exactly 174 entities, every class name unique', () => {
expect(ALL_ENTITIES.length).toBe(174);
it('ENT-003: exactly 179 entities, every class name unique', () => {
expect(ALL_ENTITIES.length).toBe(179);
const names = ALL_ENTITIES.map((s) => s.meta.className);
expect(new Set(names).size).toBe(names.length);
});
@@ -67,7 +67,10 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
// id, transport, mailbox; mail_ingest_messages: id, transport, dedupe_hash, user_id, size; mail_ingest_candidates:
// id, message_id, user_id (each row is written whole by the mail import, which always knows all of them).
// + trip_addon_overrides: trip_id, addon_id, enabled (an override is only ever written whole, by the trip owner).
const KNOWN_UNINITIALISED_NOT_NULL_SCALARS = 635;
// + user_places: id, user_id, name; user_place_links: id, user_place_id, user_id; user_place_merges: id, user_id,
// leading_id, merged_id, moved_link_ids; user_place_merge_dismissals: id, user_id, key_a, key_b;
// trip_collection_links: id, trip_id, collection_id (each row is written whole by the places library or the trip).
const KNOWN_UNINITIALISED_NOT_NULL_SCALARS = 653;
describe('entity class fields never carry a NaN initialiser (task-4-review-shape.md, Important 1)', () => {
it('CLASSFIELD-001: new X() has no own property whose value is NaN, across all 133 entities', () => {
@@ -13,7 +13,13 @@ import { PlacesLibraryService, type LibraryUser } from '../../../../src/nest/pla
import { createSnapshotTestDb } from '../../../helpers/db-mock';
import { updateRows } from '../../../helpers/factories/rows';
import { oneByOne } from '../../../helpers/one-by-one';
import { cafeTie, expectedKeysByName, seedLibrary, type LibraryFixture } from '../../../helpers/places-library-fixture';
import {
cafeTie,
expectedKeysByName,
museumTie,
seedLibrary,
type LibraryFixture,
} from '../../../helpers/places-library-fixture';
import { resetTestDb } from '../../../helpers/test-db';
import { createTestModule, type TestModule } from '../../../helpers/test-module';
import { createTestOrm, type TestOrm } from '../../../helpers/test-orm';
@@ -148,8 +154,7 @@ describe('PlacesLibraryService.list', () => {
...cafeTie(f),
`list:${f.saved.hiddenCopy.id}`,
`list:${f.saved.lunch.id}`,
`list:${f.saved.namesake.id}`,
`trip:${f.places.museum.id}`,
...museumTie(f),
]);
expect(await by({ trip_id: f.rome.id })).toEqual([`trip:${f.places.forum.id}`]);
expect(await by({ status: 'visited' })).toEqual([`list:${f.saved.pantheon.id}`]);