u-foo 2.3.11 → 2.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  const { getTimestamp, readJSON, writeJSON } = require("../bus/utils");
2
+ const { appendAgentRegistryDiagnostic, summarizeAgents } = require("./agentRegistryDiagnostics");
2
3
 
3
4
  const AGENTS_SCHEMA_VERSION = 1;
4
5
 
@@ -89,9 +90,23 @@ function normalizeAgentsData(data) {
89
90
  function loadAgentsData(filePath) {
90
91
  const data = readJSON(filePath, null);
91
92
  if (!data) {
93
+ appendAgentRegistryDiagnostic(filePath, "load_agents_empty", {
94
+ source: "ufoo.agentsStore.loadAgentsData",
95
+ reason: "missing_or_unreadable_registry",
96
+ });
92
97
  return normalizeAgentsData({});
93
98
  }
94
- return normalizeAgentsData(data);
99
+ const normalized = normalizeAgentsData(data);
100
+ const beforeSummary = summarizeAgents(data);
101
+ const afterSummary = summarizeAgents(normalized);
102
+ if (JSON.stringify(beforeSummary) !== JSON.stringify(afterSummary)) {
103
+ appendAgentRegistryDiagnostic(filePath, "load_agents_normalized", {
104
+ source: "ufoo.agentsStore.loadAgentsData",
105
+ before: beforeSummary,
106
+ after: afterSummary,
107
+ });
108
+ }
109
+ return normalized;
95
110
  }
96
111
 
97
112
  function parseTimestampMs(value) {
@@ -125,13 +140,27 @@ function mergeExternalActivityFields(targetMeta, diskMeta) {
125
140
  }
126
141
  }
127
142
 
128
- function saveAgentsData(filePath, data) {
143
+ function saveAgentsData(filePath, data, options = {}) {
144
+ const source = typeof options.source === "string" && options.source
145
+ ? options.source
146
+ : "ufoo.agentsStore.saveAgentsData";
129
147
  const normalized = normalizeAgentsData(data);
130
148
 
131
149
  // Merge externally-managed fields from disk to avoid daemon in-memory writes
132
150
  // overwriting fresher runner/notifier state updates.
133
151
  const disk = readJSON(filePath, null);
134
152
  if (disk && disk.agents && normalized.agents) {
153
+ const droppedIds = Object.keys(disk.agents)
154
+ .filter((id) => !Object.prototype.hasOwnProperty.call(normalized.agents, id))
155
+ .sort();
156
+ if (droppedIds.length > 0) {
157
+ appendAgentRegistryDiagnostic(filePath, "save_agents_dropping_disk_entries", {
158
+ source,
159
+ dropped_ids: droppedIds,
160
+ disk: summarizeAgents(disk),
161
+ next: summarizeAgents(normalized),
162
+ });
163
+ }
135
164
  for (const [id, diskMeta] of Object.entries(disk.agents)) {
136
165
  if (!diskMeta || typeof diskMeta !== "object") continue;
137
166
  const targetMeta = normalized.agents[id];
@@ -140,6 +169,13 @@ function saveAgentsData(filePath, data) {
140
169
  }
141
170
  }
142
171
 
172
+ const nextSummary = summarizeAgents(normalized);
173
+ if (nextSummary.count === 0 || options.trace === true) {
174
+ appendAgentRegistryDiagnostic(filePath, "save_agents_data", {
175
+ source,
176
+ next: nextSummary,
177
+ });
178
+ }
143
179
  writeJSON(filePath, normalized);
144
180
  }
145
181