1
0
Fork 0

Compare commits

...

3 commits

Author SHA1 Message Date
c64d56b830 v0.12.17 - superstructure interiors, bomperator prediction fixes 2026-10-21 02:15:00 -04:00
596e17e8d8 docs: add v0.12.17 changelog entry 2026-10-21 02:14:53 -04:00
1738a66e40 test: isolate locker-sync and award-automation specs from cross-file db state
Vitest 4 orders serial test files by cached durations, so adding the interior
suite reshuffled the schedule and exposed two order-dependent specs.

- arma-locker-sync: floor the apply-command scan at a beforeAll id baseline and
  assert the two enqueue tests via per-test id deltas (the pattern the echo-guard
  describe already used) instead of absolute totals that accumulate rows when
  foreign online game-servers change enqueue fan-out
- award-automation: scope every evaluateAwardRules call to this file's ruleIds,
  and track veteran/rookie USER ids separately from PROFILE ids because plans
  key on userId while makeUser returned profile ids; equality only held while
  both sequences stayed aligned
2026-10-21 02:14:43 -04:00
4 changed files with 66 additions and 17 deletions

View file

@ -1,5 +1,22 @@
# Changelog
# v0.12.17
The Superstructure has an interior now. Members walk a floorplan, clear rubble for scrap, force open sealed rooms, upgrade spaces, keep stations running, and collect job output even while offline.
### Features
- **Superstructure Interiors.** A new Interiors entry under Logistics opens the floorplan. Hotspots show each room's state; the room sheet runs the work: open sealed doors, clean junk for scrap, upgrade levels, repair broken fixtures, and start station recipes. Jobs progress in real time, room output waits in an output slot until collected, and you get a notification (with a Discord DM when linked) the moment a job is ready to collect.
- **Interior authoring.** Admins build interiors from the structure blueprint: rooms with hotspot coordinates, upgrade levels with typed effects, station recipes paying out resources or assets, fixtures, decay settings, and junk loot tables. The floorplan snapshots when a live instance is first entered, so later edits never retarget rooms members are using. Per-room and whole-interior access mirror item-storage sharing.
- **Game Rules switches.** Interior condition decay runs only while `decayEnabled` is on and scales with `decayMultiplier`. Asset (Arma item) outputs park as collectible until `assetOutputsEnabled` is turned on.
### Fixes
- **Interiors.** Floorplan snapshots bootstrap lazily on first entry, and per-room access rules are enforced on every interior action rather than only at the door.
- **Bomperator.** The client-side prediction no longer loses time against the server clock or disagrees on ghost charges: it advances by real elapsed time, releases held keys when the tab hides, replays optimistic charges in the server estimate, and clamps the replay clock so an acknowledged-late input can no longer inflate the estimate into a phantom lead.
---
# v0.12.16
Bomperator matches on the live arena feel steady again, and the arena reads more clearly at a glance.

View file

@ -1,6 +1,6 @@
{
"name": "polaris-task-force",
"version": "0.12.16",
"version": "0.12.17",
"description": "Web app for the Arma 3 unit Polaris Task Force. Uses Next.js for client- and server-side rendering, with a Postgres database and some other neat libraries.",
"license": "MIT",
"type": "module",

View file

@ -36,6 +36,9 @@ let blueprintId: number;
let structureId: number;
let lockerId: number;
let serverId: number;
// Highest arma-commands id when this file starts (set in beforeAll). Rows at or
// below it belong to earlier spec files and must never affect total counts here.
let cmdBaseline = 0;
const commandIds: number[] = [];
let eventSeq = 0;
@ -55,7 +58,8 @@ async function findLockerApplyCommands(): Promise<{ id: number; payload: unknown
const found = await payload.find({
collection: "arma-commands",
where: { type: { equals: "locker.apply" } },
limit: 100,
sort: "-id",
limit: 200,
depth: 0,
overrideAccess: true,
});
@ -65,6 +69,7 @@ async function findLockerApplyCommands(): Promise<{ id: number; payload: unknown
// vitest's timing-based file order put those files first).
return found.docs
.filter((doc) => {
if (doc.id <= cmdBaseline) return false;
const commandPayload = (doc as { payload?: unknown }).payload;
const instanceRef = Array.isArray(commandPayload) ? commandPayload[0] : undefined;
return (
@ -172,6 +177,18 @@ describe("Arma locker sync", () => {
depth: 0,
});
structureId = structure.id;
// Isolate from arma-commands rows left by earlier spec files (foreign online
// servers change locker fan-out and pollute the total-count assertions).
const latest = await payload.find({
collection: "arma-commands",
where: { id: { greater_than: 0 } },
sort: "-id",
limit: 1,
depth: 0,
overrideAccess: true,
});
cmdBaseline = (latest.docs[0]?.id as number | undefined) ?? 0;
});
afterAll(async () => {
@ -407,9 +424,16 @@ describe("Arma locker sync", () => {
});
serverId = server.id;
// Delta-scoped, not absolute: earlier sections of this file enqueue their
// own applies once any game-server (ours or a foreign leftover) is online,
// so only rows created by THIS event may be counted.
const beforeIds = new Set((await findLockerApplyCommands()).map((command) => command.id));
await processLockerEvent(payload, lockerEvent("locker.request", [`personal:${STEAM_ID}`], serverId));
const commands = await findLockerApplyCommands();
const commands = (await findLockerApplyCommands()).filter(
(command) => !beforeIds.has(command.id),
);
commandIds.push(...commands.map((command) => command.id));
expect(commands).toHaveLength(1);
const [instanceRef, stock] = commands[0].payload as [string, [string, number][]];
@ -419,9 +443,10 @@ describe("Arma locker sync", () => {
});
it("enqueues nothing for unknown instances", async () => {
const beforeIds = new Set((await findLockerApplyCommands()).map((command) => command.id));
await processLockerEvent(payload, lockerEvent("locker.request", [`structure:${RUN}-missing`], serverId));
const commands = await findLockerApplyCommands();
expect(commands).toHaveLength(1);
const fresh = (await findLockerApplyCommands()).filter((command) => !beforeIds.has(command.id));
expect(fresh).toHaveLength(0);
});
});

View file

@ -38,8 +38,12 @@ describe("Award automation sweeper", () => {
let tier1Id: number;
let tier2Id: number;
let tier3Id: number;
// Award plans are keyed by USER id; these vars hold PROFILE ids, so track
// both: they only coincide while user/profile sequences stay aligned.
let veteranId: number;
let rookieId: number;
let veteranUserId: number;
let rookieUserId: number;
let ruleIds: number[] = [];
async function makeAward(name: string, seriesTier?: number): Promise<number> {
@ -59,7 +63,7 @@ describe("Award automation sweeper", () => {
return created.id;
}
async function makeUser(username: string): Promise<number> {
async function makeUser(username: string): Promise<{ userId: number; profileId: number }> {
const user = (await payload.create({
collection: "users",
data: {
@ -80,7 +84,7 @@ describe("Award automation sweeper", () => {
overrideAccess: true,
});
if (!profiles.docs[0]) throw new Error(`profile not auto-created for ${username}`);
return profiles.docs[0].id;
return { userId: user.id, profileId: profiles.docs[0].id };
}
async function makeRule(rule: {
@ -131,15 +135,17 @@ describe("Award automation sweeper", () => {
tier2Id = await makeAward(`${RUN} YOS Silver`, 2);
tier3Id = await makeAward(`${RUN} YOS Gold`, 3);
const veteranProfileId = await makeUser("veteran");
veteranId = veteranProfileId;
const rookieProfileId = await makeUser("rookie");
rookieId = rookieProfileId;
const veteran = await makeUser("veteran");
veteranId = veteran.profileId;
veteranUserId = veteran.userId;
const rookie = await makeUser("rookie");
rookieId = rookie.profileId;
rookieUserId = rookie.userId;
// Veteran: enlisted 3 years ago, 150 contribution XP.
await payload.update({
collection: "profiles",
id: veteranProfileId,
id: veteranId,
data: {
dossier: { enlistmentDate: new Date(Date.now() - 3 * YEAR_MS).toISOString() },
progression: { contributions: { xpEarned: 150 } },
@ -150,7 +156,7 @@ describe("Award automation sweeper", () => {
// Rookie: enlisted 6 months ago, 10 XP.
await payload.update({
collection: "profiles",
id: rookieProfileId,
id: rookieId,
data: {
dossier: { enlistmentDate: new Date(Date.now() - 0.5 * YEAR_MS).toISOString() },
progression: { contributions: { xpEarned: 10 } },
@ -191,15 +197,16 @@ describe("Award automation sweeper", () => {
});
it("dry run plans grants and upgrades without writing anything", async () => {
const result = await evaluateAwardRules(payload, { dryRun: true });
const result = await evaluateAwardRules(payload, { dryRun: true, ruleIds });
expect(result.dryRun).toBe(true);
expect(result.rulesEvaluated).toBe(4); // inactive rule excluded
const veteranPlans = result.plans.filter((p) => p.userId === veteranId);
const veteranPlans = result.plans.filter((p) => p.userId === veteranUserId);
expect(veteranPlans.map((p) => p.awardId).sort()).toEqual(
[medalId, tier1Id, tier2Id].sort(),
);
expect(result.plans.some((p) => p.userId === rookieUserId)).toBe(false);
const upgradePlan = result.plans.find((p) => p.kind === "upgrade");
expect(upgradePlan?.awardId).toBe(tier2Id);
expect(upgradePlan?.replacesAwardId).toBe(tier1Id);
@ -213,7 +220,7 @@ describe("Award automation sweeper", () => {
});
it("apply writes grants and upgrades, then is idempotent", async () => {
const applied = await evaluateAwardRules(payload);
const applied = await evaluateAwardRules(payload, { ruleIds });
expect(applied.granted).toBe(2); // medal + tier 1
expect(applied.upgraded).toBe(1); // tier 1 -> tier 2 in place
@ -229,7 +236,7 @@ describe("Award automation sweeper", () => {
expect(await profileAwards(rookieId)).toHaveLength(0);
// Second run: nothing new to grant.
const rerun = await evaluateAwardRules(payload);
const rerun = await evaluateAwardRules(payload, { ruleIds });
expect(rerun.plans).toHaveLength(0);
expect(rerun.skips.some((s) => s.reason === "already-held")).toBe(true);
expect(await profileAwards(veteranId)).toHaveLength(2);