Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.
HTML agent-skillsai-agentsarchitecture-diagramclaude-codeclaude-skillscodexcoding-agentsdeepseek-harnessdeveloper-toolsdiagramsdiagrams-as-codedsh-pluginflowchartllmmermaidopencodesequence-diagramsoftware-architecturesystem-designvisualization
ci(dsh): retry transient runtime installs
tt-a1ie469147c36ed
diff --git a/integrations/deepseek-harness/scripts/distribution-acceptance.mjs b/integrations/deepseek-harness/scripts/distribution-acceptance.mjsindex 36fd4298..e40916fd 100644--- a/integrations/deepseek-harness/scripts/distribution-acceptance.mjs+++ b/integrations/deepseek-harness/scripts/distribution-acceptance.mjs@@ -5,6 +5,7 @@ import os from 'node:os';import path from 'node:path';import { fileURLToPath, pathToFileURL } from 'node:url';import { spawnCli, spawnCliSync } from './resolve-cli.mjs';+import { runWithTransientNetworkRetry } from './transient-retry.mjs';const here = path.dirname(fileURLToPath(import.meta.url));const integrationRoot = path.resolve(here, '..');@@ -232,28 +233,39 @@ const dshEnv = {npm_config_update_notifier: 'false',};-// Install the pinned host once, as a user-level global install would. Keeping-// this separate from plugin mutation makes a slow first-time npm download-// distinguishable from `dsh plugin add`, especially on Windows runners.-const runtimeInstall = run('npm', [- 'install',- '--prefix', dshRuntime,- '--no-save',- '--package-lock=false',- '--no-audit',- '--no-fund',- '--foreground-scripts',- '--loglevel=warn',- DSH_SPEC,-], {- cwd: scratch,- env: dshEnv,- // Stream npm lifecycle diagnostics without polluting the JSON-only receipt- // written to this process's stdout.- stdio: ['ignore', 2, 2],- timeout: DSH_RUNTIME_INSTALL_TIMEOUT,+// Install the pinned host separately from plugin mutation so a slow npm+// download remains distinguishable from `dsh plugin add`. Retry only a bounded+// set of transient network failures, rebuilding the install root each time.+const runtimeInstallOutcome = runWithTransientNetworkRetry((attempt) => {+ fs.rmSync(dshRuntime, { recursive: true, force: true });+ fs.mkdirSync(dshRuntime);+ if (attempt > 1) {+ process.stderr.write(`Retrying transient DSH runtime install (attempt ${attempt}/2)\n`);+ }+ return run('npm', [+ 'install',+ '--prefix', dshRuntime,+ '--no-save',+ '--package-lock=false',+ '--no-audit',+ '--no-fund',+ '--foreground-scripts',+ '--loglevel=warn',+ DSH_SPEC,+ ], {+ cwd: scratch,+ env: dshEnv,+ // Stream npm lifecycle diagnostics without polluting the JSON-only receipt+ // written to this process's stdout.+ stdio: ['ignore', 2, 2],+ timeout: DSH_RUNTIME_INSTALL_TIMEOUT,+ });+});+const runtimeInstall = runtimeInstallOutcome.result;+requireStatus('dsh-runtime-install', runtimeInstall, {+ command: `npm install ${DSH_SPEC}`,+ attempts: runtimeInstallOutcome.attempts,});-requireStatus('dsh-runtime-install', runtimeInstall, { command: `npm install ${DSH_SPEC}` });const dshPackageRoot = path.join(dshRuntime, 'node_modules', '@deepseek-ai', 'dsh');const dshManifest = JSON.parse(fs.readFileSync(path.join(dshPackageRoot, 'package.json'), 'utf8'));const dshBin = path.join(dshPackageRoot, 'lib', 'bin.js');@@ -263,7 +275,10 @@ if (dshManifest.version !== DSH_SPEC.slice(DSH_SPEC.lastIndexOf('@') + 1) || !fsbinExists: fs.existsSync(dshBin),});}-pass('dsh-runtime-install', { version: dshManifest.version });+pass('dsh-runtime-install', {+ version: dshManifest.version,+ attempts: runtimeInstallOutcome.attempts,+});function dsh(args, options = {}) {return run(process.execPath, [dshBin, ...args], {diff --git a/integrations/deepseek-harness/scripts/transient-retry.mjs b/integrations/deepseek-harness/scripts/transient-retry.mjsnew file mode 100644index 00000000..d1efa32a--- /dev/null+++ b/integrations/deepseek-harness/scripts/transient-retry.mjs@@ -0,0 +1,23 @@+const TRANSIENT_NETWORK_CODES = ['ETIMEDOUT', 'ECONNRESET', 'EAI_AGAIN'];++export function isTransientNetworkFailure(result = {}) {+ const details = [+ result.error?.code,+ result.error?.message,+ result.stderr,+ result.stdout,+ ].filter(Boolean).join('\n').toUpperCase();+ return TRANSIENT_NETWORK_CODES.some((code) => details.includes(code));+}++export function runWithTransientNetworkRetry(runAttempt, { maxAttempts = 2 } = {}) {+ let result;+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {+ result = runAttempt(attempt);+ if (!result.error && result.status === 0) return { result, attempts: attempt };+ if (attempt === maxAttempts || !isTransientNetworkFailure(result)) {+ return { result, attempts: attempt };+ }+ }+ return { result, attempts: maxAttempts };+}diff --git a/integrations/deepseek-harness/test/package-contract.test.mjs b/integrations/deepseek-harness/test/package-contract.test.mjsindex 5043ca34..7abfa0a9 100644--- a/integrations/deepseek-harness/test/package-contract.test.mjs+++ b/integrations/deepseek-harness/test/package-contract.test.mjs@@ -75,8 +75,8 @@ test('distribution acceptance reserves stdout for its machine-readable JSON recepath.join(integrationRoot, 'scripts', 'distribution-acceptance.mjs'),'utf8',);- const runtimeInstall = source.match(/const runtimeInstall = run\([\s\S]*?\n\}\);/)?.[0] || '';- assert.match(runtimeInstall, /stdio:\s*\['ignore',\s*2,\s*2\]/);+ assert.match(source, /runWithTransientNetworkRetry/);+ assert.match(source, /stdio:\s*\['ignore',\s*2,\s*2\]/);assert.doesNotMatch(source, /stdio:\s*['"]inherit['"]/);assert.equal([...source.matchAll(/process\.stdout\.write/g)].length, 2);});diff --git a/integrations/deepseek-harness/test/transient-retry.test.mjs b/integrations/deepseek-harness/test/transient-retry.test.mjsnew file mode 100644index 00000000..43df00d0--- /dev/null+++ b/integrations/deepseek-harness/test/transient-retry.test.mjs@@ -0,0 +1,44 @@+import assert from 'node:assert/strict';+import test from 'node:test';++import {+ isTransientNetworkFailure,+ runWithTransientNetworkRetry,+} from '../scripts/transient-retry.mjs';++test('retries one transient network failure and reports both attempts', () => {+ const results = [+ { status: null, error: Object.assign(new Error('spawnSync npm ETIMEDOUT'), { code: 'ETIMEDOUT' }) },+ { status: 0, stdout: '', stderr: '' },+ ];+ const attempts = [];++ const outcome = runWithTransientNetworkRetry((attempt) => {+ attempts.push(attempt);+ return results.shift();+ });++ assert.equal(outcome.result.status, 0);+ assert.equal(outcome.attempts, 2);+ assert.deepEqual(attempts, [1, 2]);+});++test('does not retry a non-network installation failure', () => {+ let calls = 0;+ const outcome = runWithTransientNetworkRetry(() => {+ calls += 1;+ return { status: 1, stderr: 'npm ERR! lifecycle script failed' };+ });++ assert.equal(outcome.result.status, 1);+ assert.equal(outcome.attempts, 1);+ assert.equal(calls, 1);+});++test('recognizes only the bounded set of transient network failures', () => {+ for (const code of ['ETIMEDOUT', 'ECONNRESET', 'EAI_AGAIN']) {+ assert.equal(isTransientNetworkFailure({ error: { code } }), true, code);+ assert.equal(isTransientNetworkFailure({ stderr: `request failed: ${code}` }), true, code);+ }+ assert.equal(isTransientNetworkFailure({ stderr: 'npm ERR! EACCES permission denied' }), false);+});