mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 14:36:31 +00:00
2e1dca9fe9
Settings, Integrations, wanderer gains an optional background check of the trails you imported, off until you switch it on. While on, TREK reads the short record of each such trail at most once a day (never its GPX file) and leaves a hint when the trail may have moved on: "may have changed" when only wanderer's change time moved, "changed" when its name or description proves it, and "not checkable" when the trail is gone, no longer yours or carries no change time. Nothing is ever said to be unchanged. A new hint arrives as a notification that opens the tour (a new ?place= link in the planner); the tour's provenance shows it with the source check right beside it, and the card lists all open hints in a dialog, each leading to its tour. The check reads the source in full as before and spends the hint; taking a change in stays the confirmed reimport. No tour is ever changed or deleted. The check only asks through your own connection, only about trails your account imported into trips you can still open, and stops when you switch it off, remove the connection, wanderer refuses the token (until a test passes or a new token is saved) or the admin switches wanderer off; hints and snapshots stay. A run asks at most 25 connections for at most 10 records each, one after another, and an instance that fails (an outage, a rate limit) is left alone for an hour, doubling up to two days. Server: migration 046120 adds the switch and the run bookkeeping to wanderer_connections and the tour_source_hints table (one row per snapshot, for its importer, gone with it). WandererWatchService and an hourly wanderer-watch job on the CronRegistrar live in the tours domain and read through WandererService; GET and PUT /api/integrations/wanderer/watch and GET /api/trips/:tripId/tours/wanderer/sources/:placeId/hint (place_edit, like the check) answer with @trek/shared contracts. A new user notification event, wanderer_source_hint, can be muted per channel. Saving a new token now clears what the last check said about the old one. There is no MCP tool, as for the rest of the personal wanderer connection. All 27 locales carry the strings, and the admin wiki page says what the check does.
130 lines
6.3 KiB
TypeScript
130 lines
6.3 KiB
TypeScript
import { ALL_ENTITIES } from '../../../src/db/entities';
|
|
import { TrekRepository } from '../../../src/db/repositories/_shared/trek-repository';
|
|
import { createSnapshotTestDb } from '../../helpers/db-mock';
|
|
import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
|
|
import { EntitySchema, type EntityRepository } from '@mikro-orm/core';
|
|
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
|
|
const ENTITIES_DIR = path.join(__dirname, '../../../src/db/entities');
|
|
const REPOSITORIES_DIR = path.join(__dirname, '../../../src/db/repositories');
|
|
|
|
describe('ALL_ENTITIES', () => {
|
|
it('ENT-001: lists exactly one schema per *.entity.ts file', () => {
|
|
const files = fs
|
|
.readdirSync(ENTITIES_DIR)
|
|
.filter((f) => f.endsWith('.entity.ts'))
|
|
.sort();
|
|
const names = ALL_ENTITIES.map((s) => s.name).sort();
|
|
const expected = files.map((f) => f.replace(/\.entity\.ts$/, '')).sort();
|
|
expect(names).toEqual(expected);
|
|
});
|
|
|
|
it('ENT-002: every entry is an EntitySchema with a class', () => {
|
|
for (const schema of ALL_ENTITIES) {
|
|
expect(schema).toBeInstanceOf(EntitySchema);
|
|
expect(typeof schema.meta.class).toBe('function');
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Plan 2 Task 3: every one of the 135 entities the migrated schema
|
|
* describes (120 rewritten + the 5 document-sync tables added this task,
|
|
* + push_subscriptions and google_api_usage from legacy steps 245 and 254,
|
|
* + tour_types, tours and tour_waypoints from the Tours migration,
|
|
* + scheduler_leases from the cron lease migration
|
|
* + user_sessions, the session rows behind revocable session tokens
|
|
* + ferrata_tiles, the stored via ferrata grid cells
|
|
* + paddle_regions, paddle_features and tour_obstacle_reviews, the paddle obstacle data and decisions
|
|
* + trip_journal_links and trip_journal_link_members, the journal a trip shows and who it is open to
|
|
* + paddle_water_graphs and paddle_region_requests, a region's water network and the regions that wait for an admin
|
|
* + tour_station_visits, how far a city walk got on one of its days
|
|
* + tour_change_steps, the changes to a tour saved from a confirmed proposal
|
|
* + tour_activities, the recorded tracks assigned to a tour
|
|
* + tour_activity_exclusions, the tours a user left out of their own activity sums
|
|
* + collection_tours, the whole tours a collection keeps
|
|
* + tour_packing_links, the packing list or category a tour points at
|
|
* + tour_source_hints, what the wanderer watch found about a snapshot's source)
|
|
* 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 149 entities, every class name unique', () => {
|
|
expect(ALL_ENTITIES.length).toBe(149);
|
|
const names = ALL_ENTITIES.map((s) => s.meta.className);
|
|
expect(new Set(names).size).toBe(names.length);
|
|
});
|
|
|
|
/**
|
|
* Task 1's review flagged this binding as otherwise unpinned: dropping an
|
|
* entity's `repository: () => XRepository` mutation stayed green in every
|
|
* gate up to here (task-1-review.md, minor 1). `em.getRepository(X)` must
|
|
* return an instance of the exact repository class
|
|
* `src/db/repositories/<Name>.repository.ts` exports, for every entity —
|
|
* the 120 the generator wrote a stub for this task plus the 5 pre-existing,
|
|
* hand-written ones (`Days`, `DayNotes`, `Trips`, `BudgetCategoryOrder`,
|
|
* `VacayUserSettings`) it left untouched.
|
|
*/
|
|
describe('ENT-004: em.getRepository(X) is an instance of X.repository.ts', () => {
|
|
let t: TestOrm;
|
|
const testDb = createSnapshotTestDb();
|
|
|
|
beforeAll(async () => {
|
|
t = await createTestOrm(testDb);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await t.close();
|
|
testDb.close();
|
|
});
|
|
|
|
it('every entity resolves to its own repository class', async () => {
|
|
const failures: string[] = [];
|
|
for (const schema of ALL_ENTITIES) {
|
|
const className = schema.meta.className;
|
|
const repoFile = path.join(REPOSITORIES_DIR, `${className}.repository.ts`);
|
|
if (!fs.existsSync(repoFile)) {
|
|
failures.push(`${className}: no src/db/repositories/${className}.repository.ts file`);
|
|
continue;
|
|
}
|
|
const mod: Record<string, unknown> = await import(
|
|
/* @vite-ignore */ `../../../src/db/repositories/${className}.repository`
|
|
);
|
|
const RepoClass = mod[`${className}Repository`];
|
|
if (typeof RepoClass !== 'function') {
|
|
failures.push(`${className}: repository module has no exported ${className}Repository class`);
|
|
continue;
|
|
}
|
|
const repo: EntityRepository<object> = t.em.getRepository(schema.class as new () => object);
|
|
if (!(repo instanceof (RepoClass as abstract new (...args: never[]) => unknown))) {
|
|
failures.push(`${className}: em.getRepository() did not return a ${className}Repository instance`);
|
|
}
|
|
// Task 7 review, H2 carry-list item 1: the `extends EntityRepository`
|
|
// ratchet made self-enforcing — every bound repository must also be
|
|
// a TrekRepository (validateRequestContext + the disableIdentityMap
|
|
// read default), not just an instance of its own named class.
|
|
if (!(repo instanceof TrekRepository)) {
|
|
failures.push(`${className}: em.getRepository() did not return a TrekRepository instance`);
|
|
}
|
|
}
|
|
expect(failures).toEqual([]);
|
|
});
|
|
|
|
// Task 7 review, H2: a source-scan companion to the instanceof check
|
|
// above — belt and suspenders against a repository that extends
|
|
// TrekRepository indirectly (or not through this loop's import path).
|
|
it('SCAN-001: exactly one repository file extends EntityRepository directly — the base class itself', () => {
|
|
const files = fs.readdirSync(REPOSITORIES_DIR).filter((f) => f.endsWith('.repository.ts'));
|
|
const hits: string[] = [];
|
|
for (const file of files) {
|
|
const content = fs.readFileSync(path.join(REPOSITORIES_DIR, file), 'utf-8');
|
|
if (/\bextends\s+EntityRepository\b/.test(content)) hits.push(file);
|
|
}
|
|
expect(hits).toEqual([]); // the base class lives in _shared/, not matched by *.repository.ts
|
|
});
|
|
});
|
|
});
|