Repository navigation
feat(code-analysis): review pinned PR commits offline #1443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
360ee57
759fc9e
df7065f
2667e9e
0c0377c
c7f3e97
2132908
ac925e7
73bbc3e
73abe22
1a37e82
716ba72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ import { DiagnosticError, fail } from '../core/index.mjs'; | |
| import { analysisStartCommand } from '../lib/task-command.mjs'; | ||
| import { standaloneShell } from '../overlay/standalone.mjs'; | ||
| import { clientAsset } from '../overlay/client-assets.mjs'; | ||
| import { preparePullRequest } from '../lib/pull-request.mjs'; | ||
| import { preparePullRequest, resolveLocalPullRequest, resolvePullRequest } from '../lib/pull-request.mjs'; | ||
|
|
||
| const execute = promisify(execFile); | ||
| const here = path.dirname(fileURLToPath(import.meta.url)); | ||
|
|
@@ -36,9 +36,12 @@ const TASK_BODY_LIMIT = 16 * 1024; | |
|
|
||
| // Runs one analysis in a child process and resolves with its receipt. | ||
| // Failures come back as the worker's structured diagnostics. | ||
| export function runWorker(options) { | ||
| export function runWorker(options, { offline = false } = {}) { | ||
| return new Promise((resolve, reject) => { | ||
| const child = spawn(process.execPath, [worker], { stdio: ['pipe', 'pipe', 'pipe'] }); | ||
| const child = spawn(process.execPath, [worker], { | ||
| stdio: ['pipe', 'pipe', 'pipe'], | ||
| ...(offline ? { env: { ...process.env, GIT_NO_LAZY_FETCH: '1', GIT_ALLOW_PROTOCOL: '', CARGO_NET_OFFLINE: 'true', RUSTUP_AUTO_INSTALL: '0' } } : {}), | ||
| }); | ||
| let stdout = '', stderr = ''; | ||
| child.stdout.setEncoding('utf8').on('data', (chunk) => { stdout += chunk; }); | ||
| child.stderr.setEncoding('utf8').on('data', (chunk) => { stderr += chunk; }); | ||
|
|
@@ -62,7 +65,7 @@ export function missingAnalysisDependencies(root = moduleRoot) { | |
|
|
||
| export const USAGE = `Usage: | ||
| archify code-analysis serve <repo-root> --out <dir> [--ir <architecture.json>] [--locale en|zh-CN] | ||
| [--pr <GitHub-URL-or-number>] [--repository OWNER/REPO] [--scope path] [--language ts|py|java|go|rust|c|cpp] [--map overlay-map.json] [--config file.json] | ||
| [--pr <GitHub-URL-or-number> [--repository OWNER/REPO] | --base <commit> --head <commit>] [--scope path] [--language ts|py|java|go|rust|c|cpp] [--map overlay-map.json] [--config file.json] | ||
| [--baseline baseline.json] [--quality standard|showcase] | ||
|
|
||
| Without --ir, opens a standalone workbench with Atlas and analyzes on page load. | ||
|
|
@@ -82,13 +85,18 @@ export function parseArgs(argv) { | |
| const options = {}; | ||
| for (let i = 0; i < rest.length; i += 2) { | ||
| const key = rest[i]; | ||
| if (!['--ir', '--out', '--language', '--config', '--map', '--quality', '--baseline', '--locale', '--pr', '--repository', '--scope'].includes(key) || !rest[i + 1] || rest[i + 1].startsWith('--')) throw usageError(`Invalid option: ${key}\n${USAGE}`); | ||
| if (!['--ir', '--out', '--language', '--config', '--map', '--quality', '--baseline', '--locale', '--pr', '--repository', '--scope', '--base', '--head'].includes(key) || !rest[i + 1] || rest[i + 1].startsWith('--')) throw usageError(`Invalid option: ${key}\n${USAGE}`); | ||
| if (['--base', '--head'].includes(key) && options[key]) throw usageError('Pass each pinned commit option once.'); | ||
| options[key] = rest[i + 1]; | ||
| } | ||
| if (!options['--out']) throw usageError(`serve requires --out\n${USAGE}`); | ||
| if (options['--map'] && !options['--ir']) throw usageError('--map requires --ir: mapping belongs to an authored architecture diagram.'); | ||
| if (options['--locale'] && !['en', 'zh-CN'].includes(options['--locale'])) throw usageError('--locale must be en or zh-CN.'); | ||
| if (!options['--pr'] && (options['--repository'] || options['--scope'])) throw usageError('--repository and --scope require --pr.'); | ||
| const base = options['--base'], head = options['--head']; | ||
| if (Boolean(base) !== Boolean(head)) throw usageError('--base and --head must be provided together.'); | ||
| if (base && options['--pr']) throw usageError('Choose either --pr or --base with --head.'); | ||
| if (!options['--pr'] && options['--repository']) throw usageError('--repository requires --pr.'); | ||
| if (!options['--pr'] && !base && options['--scope']) throw usageError('--scope requires --pr or --base with --head.'); | ||
| return { repo, options }; | ||
| } | ||
|
|
||
|
|
@@ -99,7 +107,9 @@ export async function prepareAnalysisSession(argv) { | |
| const input = irBytes ? JSON.parse(irBytes.toString('utf8')) : null; | ||
| const locale = analysisLocale(options['--locale'] || input?.meta?.locale); | ||
| const doc = input ? { ...input, meta: { ...input.meta, locale } } : null; | ||
| const pullRequest = options['--pr'] ? await (await import('../lib/pull-request.mjs')).resolvePullRequest(root, options['--pr'], options['--repository'], options['--scope']) : null; | ||
| const pullRequest = options['--base'] | ||
| ? await resolveLocalPullRequest(root, options['--base'], options['--head'], options['--scope']) | ||
| : options['--pr'] ? await resolvePullRequest(root, options['--pr'], options['--repository'], options['--scope']) : null; | ||
|
Comment on lines
+110
to
+112
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Network requests during offline diagram review With Learn moreThe pinned-mode branch selects local commits, but only the later analysis workers get offline environment settings. When an authored diagram is supplied, diagram delivery runs first with the caller's environment. Its update check is enabled by default and fetches the release manifest when there is no fresh cache and time remains. The pinned diagram regression already sets the disable flag itself, so it does not cover the command's default behavior. Example: Run Recommended fix: Pass Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| fs.mkdirSync(out, { recursive: true }); | ||
|
|
||
| // 1. Archify delivers the diagram. Repository evidence is checked when the IR pins a repository. | ||
|
|
@@ -142,6 +152,7 @@ export async function prepareAnalysisSession(argv) { | |
| config: options['--config'] ? path.resolve(options['--config']) : null, | ||
| map: options['--map'] ? path.resolve(options['--map']) : null, | ||
| baseline: baselineFile, pr: options['--pr'], repository: options['--repository'], scope: options['--scope'], | ||
| base: options['--base'], head: options['--head'], | ||
| }), shell: process.platform === 'win32' ? 'cmd.exe' : 'POSIX sh' }; | ||
| return { root, ir, out, options, irBytes, doc, locale, delivered, baselineFile, resume, pullRequest }; | ||
| } | ||
|
|
@@ -150,6 +161,7 @@ export async function runSessionAnalysis({ root, ir, doc, locale, delivered, out | |
| const analysisDir = path.join(out, 'analysis'); | ||
| const next = path.join(out, `analysis.next-${randomBytes(6).toString('hex')}`); | ||
| let capture = null; | ||
| const offline = Boolean(pullRequest?.local); | ||
| try { | ||
| let language = options['--language'] || null, config = options['--config'] ? path.resolve(options['--config']) : null; | ||
| if (pullRequest) { | ||
|
|
@@ -168,15 +180,15 @@ export async function runSessionAnalysis({ root, ir, doc, locale, delivered, out | |
| } | ||
| } | ||
| await runWorker({ root: capture.roots.base, out: path.join(next, 'base'), locale, language, config, | ||
| source: capture.source('base'), openAnalysis: true }); | ||
| source: capture.source('base'), openAnalysis: true, captureDriftInputs: Boolean(offline && ir && language === 'ts') }, { offline }); | ||
| } | ||
| await runWorker({ | ||
| root: capture?.roots.head || root, ir, irSnapshot: doc, html: delivered, locale, out: next, resume, openAnalysis: !ir || openAnalysis, | ||
| language, config, source: capture?.source('head') || null, | ||
| pullRequest: capture ? { pr: capture.pr, scope: capture.scope, changedFiles: capture.changedFiles, manifests: capture.manifests, sourceRoot: capture.roots.head, baseSourceRoot: capture.roots.base, sourceGitRoot: capture.sourceGitRoot } : null, | ||
| map: options['--map'] ? path.resolve(options['--map']) : null, baseline: fs.existsSync(baselineFile) ? baselineFile : null, | ||
| previous: capture ? path.join(next, 'base/findings.json') : path.join(analysisDir, 'findings.json'), | ||
| }); | ||
| }, { offline }); | ||
| } catch (error) { | ||
| fs.rmSync(next, { recursive: true, force: true }); | ||
| if (capture) fs.rmSync(capture.directory, { recursive: true, force: true }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal review confirmation is missing for head
716ba728e093753a06251944741138998035edea.The PR body records personal confirmations only for earlier heads. Its latest synchronization section names
1a37e825and states that it awaits contributor review. No PR body section, issue comment, or review names716ba728. Green CI for that head cannot supply the confirmation.Scope is not the gap. The reviewer’s comment records scope agreement for the offline
--base/--headentry point, and that agreement still applies.Detailed code review and review delegation stay deferred until the accountable contributor posts a personal review confirmation that names
716ba728e093753a06251944741138998035edea. Earlier evidence can be reused where the intervening changes do not invalidate it.Sources: Coding guidelines, Path instructions