commitshow 0.2.1 → 0.2.2
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.
- package/dist/commands/audit.js +9 -2
- package/dist/lib/api.js +24 -10
- package/package.json +1 -1
package/dist/commands/audit.js
CHANGED
|
@@ -27,7 +27,14 @@ export async function audit(args) {
|
|
|
27
27
|
// already have the snapshot. Covers all full-audition projects.
|
|
28
28
|
// --refresh / --force skips this entirely and goes straight to audit-preview
|
|
29
29
|
// with force=true (counts against IP + URL + global rate limits).
|
|
30
|
-
|
|
30
|
+
//
|
|
31
|
+
// We always look up `existing` (even on --force) so that we can capture the
|
|
32
|
+
// pre-refresh `last_analysis_at` baseline and poll for a *newer* snapshot.
|
|
33
|
+
// Without that baseline, polling sees the stale snapshot's timestamp as
|
|
34
|
+
// "ready" and returns it immediately.
|
|
35
|
+
const existing = await findProjectByGithubUrl(target.github_url);
|
|
36
|
+
const project = force ? null : existing;
|
|
37
|
+
const refreshBaseline = force ? (existing?.last_analysis_at ?? null) : null;
|
|
31
38
|
if (project) {
|
|
32
39
|
const [snapshot, standing] = await Promise.all([
|
|
33
40
|
fetchLatestSnapshot(project.id),
|
|
@@ -128,7 +135,7 @@ export async function audit(args) {
|
|
|
128
135
|
const pending = result;
|
|
129
136
|
if (!asJson)
|
|
130
137
|
console.log(c.dim(' This runs the full Claude audit · ~60-90 seconds. Hang tight.'));
|
|
131
|
-
const waited = await waitForPreviewSnapshot(pending.project_id);
|
|
138
|
+
const waited = await waitForPreviewSnapshot(pending.project_id, refreshBaseline);
|
|
132
139
|
if (!waited) {
|
|
133
140
|
emitError(asJson, 'timeout', 'Preview audit is taking longer than expected. Try `commitshow status <repo>` in a minute.', target.github_url);
|
|
134
141
|
return 1;
|
package/dist/lib/api.js
CHANGED
|
@@ -77,20 +77,34 @@ export async function runPreviewAudit(githubUrl, liveUrl, opts = {}) {
|
|
|
77
77
|
return body;
|
|
78
78
|
return body;
|
|
79
79
|
}
|
|
80
|
-
/** Poll a preview job until the snapshot lands or we time out.
|
|
81
|
-
|
|
80
|
+
/** Poll a preview job until the snapshot lands or we time out.
|
|
81
|
+
*
|
|
82
|
+
* `since` (ISO timestamp) is the baseline we wait past. For an INITIAL audit
|
|
83
|
+
* on a brand-new project, leave it undefined — any snapshot wins. For a
|
|
84
|
+
* REFRESH (force=true) on an existing project, pass the project's previous
|
|
85
|
+
* `last_analysis_at` so we keep polling until a *new* snapshot lands.
|
|
86
|
+
* Without this guard, a force-refresh against an already-analyzed project
|
|
87
|
+
* returns the stale snapshot immediately because `last_analysis_at` is
|
|
88
|
+
* already truthy. (Bug seen in 0.2.1 and earlier.) */
|
|
89
|
+
export async function waitForPreviewSnapshot(projectId, since, timeoutMs = 180_000, intervalMs = 4_000) {
|
|
90
|
+
const sinceMs = since ? new Date(since).getTime() : 0;
|
|
82
91
|
const deadline = Date.now() + timeoutMs;
|
|
83
92
|
while (Date.now() < deadline) {
|
|
84
93
|
const project = await findProjectById(projectId);
|
|
85
94
|
if (project && project.last_analysis_at) {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
const lastMs = new Date(project.last_analysis_at).getTime();
|
|
96
|
+
// sinceMs === 0 → first ever audit, accept any snapshot.
|
|
97
|
+
// Otherwise require last_analysis_at to have advanced.
|
|
98
|
+
if (sinceMs === 0 || lastMs > sinceMs) {
|
|
99
|
+
const snapshot = await fetchLatestSnapshot(projectId);
|
|
100
|
+
return {
|
|
101
|
+
project,
|
|
102
|
+
snapshot,
|
|
103
|
+
standing: null,
|
|
104
|
+
is_preview: project.status === 'preview',
|
|
105
|
+
cache_hit: false,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
94
108
|
}
|
|
95
109
|
await new Promise(r => setTimeout(r, intervalMs));
|
|
96
110
|
}
|