Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: pin dormant Stacker News monitoring boundaries (#12563)

[._.]/ Adam Eivy39833d97dfdd
diff --git a/server/routes/hostControlStackerNewsMonitoring.test.js b/server/routes/hostControlStackerNewsMonitoring.test.js
index fdb8de832f..786ec68589 100644
--- a/server/routes/hostControlStackerNewsMonitoring.test.js
+++ b/server/routes/hostControlStackerNewsMonitoring.test.js
@@ -28,7 +28,7 @@ const effects = vi.hoisted(() => ({
}));
vi.mock('../services/stackerNews.js', () => ({
...effects, getAccount: async () => state.account, getTerritory: async () => state.territory,
- listTerritories: async () => [state.territory],
+ listTerritories: async () => state.territory ? [state.territory] : [],
}));
vi.mock('../services/stackerNewsScheduler.js', () => effects);
import { authGate, hostControlRouteGate } from '../services/authGate.js';
@@ -133,6 +133,15 @@ describe('Stacker News browser and monitoring authority', () => {
for (const effect of Object.values(effects)) expect(effect).not.toHaveBeenCalled();
});
+ it('keeps account re-enabling open when no territory would be monitored', async () => {
+ state.account.enabled = false;
+ state.account.monitoringEnabled = true;
+ for (const territory of [state.territory, null]) {
+ state.territory = territory;
+ expect((await call(appFor(), ['patch', `/accounts/${accountId}`, { enabled: true }])).status).toBe(200);
+ }
+ });
+
it('allows dormant inheritance and re-enabling with all monitoring disabled', async () => {
for (const operation of [
['post', '/territories', { accountId, slug: 'example' }],
diff --git a/server/routes/stackerNews.js b/server/routes/stackerNews.js
index b3bf9cff6d..2b64842ef0 100644
--- a/server/routes/stackerNews.js
+++ b/server/routes/stackerNews.js
@@ -110,7 +110,8 @@ router.patch('/accounts/:id', asyncHandler(async (req, res) => {
requireId(req.params.id, 'account ID');
const data = validateRequest(accountUpdateSchema, req.body);
if (data.monitoringEnabled === true) assertHostControl(req);
- // Re-enabling an account also re-arms saved territory monitoring.
+ // Re-enabling an account also re-arms saved territory monitoring. The
+ // scheduler never arms an account without an effectively monitored territory.
if (data.enabled === true && data.monitoringEnabled !== true) {
const current = await stackerNews.getAccount(req.params.id);
if (current && !current.enabled) {
diff --git a/server/services/stackerNewsScheduler.test.js b/server/services/stackerNewsScheduler.test.js
index b428c888ac..e335f88c10 100644
--- a/server/services/stackerNewsScheduler.test.js
+++ b/server/services/stackerNewsScheduler.test.js
@@ -26,6 +26,17 @@ describe('Stacker News scheduler', () => {
stopStackerNewsSchedulers();
});
+ it('never arms account-only monitoring without an effectively monitored territory', async () => {
+ listAccounts.mockResolvedValue([{ id: 'dormant', enabled: true, monitoringEnabled: true, monitoringIntervalMinutes: 15 }]);
+ for (const territories of [[], [{ monitoringEnabled: false }]]) {
+ listTerritories.mockResolvedValue(territories);
+ await expect(reconcileStackerNewsSchedulers()).resolves.toBe(0);
+ }
+ expect(schedule).not.toHaveBeenCalled();
+ expect(syncAccount).not.toHaveBeenCalled();
+ stopStackerNewsSchedulers();
+ });
+
it('arms a territory-level opt-in and rechecks the effective setting before syncing', async () => {
const account = { id: 'territory-opt-in', enabled: true, monitoringEnabled: false, monitoringIntervalMinutes: 30 };
listAccounts.mockResolvedValue([account]);