walkdiff 0.7.1 → 0.7.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/CHANGELOG.md +4 -1
- package/README.md +2 -2
- package/package.json +1 -1
- package/walkdiff.mjs +50 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.7.2
|
|
4
|
+
|
|
5
|
+
- **`walkdiff --version`:** shows which Walkdiff runs, and every error now ends with the version, such as `(walkdiff 0.7.2)`, so a pasted error says which release it came from. The troubleshooting guide covers "transport 'ssh' not allowed" and how to find which Walkdiff runs when several are installed.
|
|
6
|
+
- **No duplicate-code warnings on migrations:** migration files, such as db-migrate's, repeat the same template by design and must not share code, so duplicate detection now leaves them out. Rails' `db/migrate/` now also counts as a database migration for the sensitive-path check, as it already did for breaking changes.
|
|
4
7
|
|
|
5
8
|
## 0.7.1
|
|
6
9
|
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
A review companion for GitHub pull requests and GitLab merge requests. `walkdiff review <url>` fetches the
|
|
6
6
|
change, analyzes it, and serves a local report. (Working name; the project name is still an open decision.)
|
|
7
7
|
|
|
8
|
-
Status: early release, [v0.7.
|
|
8
|
+
Status: early release, [v0.7.2](CHANGELOG.md). To run it on your team's PRs, see the [pilot guide](docs/pilot.md).
|
|
9
9
|
|
|
10
10
|
**Documentation:** [getting started](docs/getting-started.md), [configuration](docs/configuration.md), [troubleshooting](docs/troubleshooting.md), [security policy](SECURITY.md).
|
|
11
11
|
|
|
@@ -98,7 +98,7 @@ Tokens and code stay on your machine, apart from the host itself, package names
|
|
|
98
98
|
|
|
99
99
|
## In CI
|
|
100
100
|
|
|
101
|
-
The GitHub Action (`navasvarela/walkdiff@v0.7.
|
|
101
|
+
The GitHub Action (`navasvarela/walkdiff@v0.7.2`) and the GitLab template (`ci/gitlab-ci.yml`) generate the report for each PR, keep it as a job artifact, and post one summary comment that is updated on each push. The [pilot guide](docs/pilot.md) has the setup. Locally, `walkdiff review` also works without a URL inside a CI job, and `walkdiff comment --report <dir> --report-url <url>` posts the summary.
|
|
102
102
|
|
|
103
103
|
## AI review
|
|
104
104
|
|
package/package.json
CHANGED
package/walkdiff.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { z } from "zod";
|
|
|
8
8
|
import { createHash, randomBytes } from "node:crypto";
|
|
9
9
|
import { Language, Parser } from "web-tree-sitter";
|
|
10
10
|
import { homedir, tmpdir } from "node:os";
|
|
11
|
-
import { existsSync } from "node:fs";
|
|
11
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
12
12
|
import { parse } from "smol-toml";
|
|
13
13
|
import Anthropic from "@anthropic-ai/sdk";
|
|
14
14
|
import { betaZodOutputFormat } from "@anthropic-ai/sdk/helpers/beta/zod";
|
|
@@ -3261,6 +3261,16 @@ async function pythonSurface(repository, paths) {
|
|
|
3261
3261
|
return (!manifest.endsWith("pyproject.toml") || PYPROJECT_BUILDS.test(texts.get(manifest) ?? "")) && listedInDunderAll(texts.get(path), name);
|
|
3262
3262
|
};
|
|
3263
3263
|
}
|
|
3264
|
+
// packages/engine/src/risk/migrationFiles.ts
|
|
3265
|
+
/**
|
|
3266
|
+
* Where frameworks keep database migrations: `migrations/` for db-migrate, knex, Sequelize,
|
|
3267
|
+
* TypeORM, Django and most others, `alembic/versions/` for Alembic, and `db/migrate/` and
|
|
3268
|
+
* `db/post_migrate/` for Rails and GitLab.
|
|
3269
|
+
*/
|
|
3270
|
+
const MIGRATION_PATH = /(^|\/)migrations?\/|(^|\/)alembic\/versions\/|(^|\/)db\/(?:post_)?migrate\//;
|
|
3271
|
+
function isMigrationPath(path) {
|
|
3272
|
+
return MIGRATION_PATH.test(path);
|
|
3273
|
+
}
|
|
3264
3274
|
// packages/engine/src/risk/breaking/migrations.ts
|
|
3265
3275
|
const SchemaChangeKind = {
|
|
3266
3276
|
DropTable: "dropTable",
|
|
@@ -3269,7 +3279,6 @@ const SchemaChangeKind = {
|
|
|
3269
3279
|
RenameColumn: "renameColumn",
|
|
3270
3280
|
ChangeType: "changeType"
|
|
3271
3281
|
};
|
|
3272
|
-
const MIGRATION_FILE = /(^|\/)migrations?\/|(^|\/)alembic\/versions\/|(^|\/)db\/(?:post_)?migrate\//;
|
|
3273
3282
|
const DOWN_FILE = /\.down\.sql$|(^|\/)U\d[^/]*\.sql$/i;
|
|
3274
3283
|
const DOWN_SECTION = /\bdef\s+down(?:grade)?\b|\bdown\s*[(:=]|\bexports\.down\b|\+goose\s+Down|\+migrate\s+Down|migrate:down/i;
|
|
3275
3284
|
const UP_SECTION = /\bdef\s+(?:up(?:grade)?|change)\b|\bup\s*[(:=]|\bexports\.up\b|\+goose\s+Up|\+migrate\s+Up|migrate:up/i;
|
|
@@ -3460,7 +3469,7 @@ function changeOnLine(lines, index) {
|
|
|
3460
3469
|
}
|
|
3461
3470
|
function isMigration(file) {
|
|
3462
3471
|
const { path, status } = file.diff;
|
|
3463
|
-
return status !== FileChangeStatus.Deleted &&
|
|
3472
|
+
return status !== FileChangeStatus.Deleted && isMigrationPath(path) && !DOWN_FILE.test(path) && !isTestPath(path) && !isThirdParty(file);
|
|
3464
3473
|
}
|
|
3465
3474
|
/** Names this PR's migrations bring into being, which nothing outside the PR can depend on yet. */
|
|
3466
3475
|
function namesCreatedInThisChange(migrations) {
|
|
@@ -6162,13 +6171,13 @@ function runProblem(result, okExitCodes, scanner) {
|
|
|
6162
6171
|
*/
|
|
6163
6172
|
async function runJscpd(request, candidates, workspace) {
|
|
6164
6173
|
if (request.disabled?.has(JSCPD.id)) return notRun(JSCPD.check, TURNED_OFF_IN_SETTINGS);
|
|
6165
|
-
const reviewable = candidates.filter((file) =>
|
|
6174
|
+
const reviewable = candidates.filter((file) => isDuplicationCandidate(file.diff.path) && hasAddedLines(file));
|
|
6166
6175
|
if (reviewable.length === 0) return {
|
|
6167
6176
|
findings: [],
|
|
6168
6177
|
checksRun: [],
|
|
6169
6178
|
notChecked: []
|
|
6170
6179
|
};
|
|
6171
|
-
const sources = (await listSourceFiles(request.repoDir, request.head)).filter((path) =>
|
|
6180
|
+
const sources = (await listSourceFiles(request.repoDir, request.head)).filter((path) => isDuplicationCandidate(path) && !request.isIgnored(path) && !CONFIG_LIKE_FILE.test(basename(path)));
|
|
6172
6181
|
if (sources.length > MAX_DUPLICATION_SOURCE_FILES) return notRun(JSCPD.check, `the repository has more than ${MAX_DUPLICATION_SOURCE_FILES} source files`);
|
|
6173
6182
|
const root = await prepareScanRoot(workspace, JSCPD.name, []);
|
|
6174
6183
|
await copySources(request, sources, root);
|
|
@@ -6188,6 +6197,15 @@ async function runJscpd(request, candidates, workspace) {
|
|
|
6188
6197
|
return notRun(JSCPD.check, `its report could not be read: ${messageOf(error)}`);
|
|
6189
6198
|
}
|
|
6190
6199
|
}
|
|
6200
|
+
/**
|
|
6201
|
+
* Tests repeat setup on purpose. Migrations are written from a template, such as db-migrate's
|
|
6202
|
+
* `setup`, `up` and `down`, and are frozen once run, so copying code into one rather than
|
|
6203
|
+
* importing it is right: the migration must not change when the app does. Either would make
|
|
6204
|
+
* every new file look like a copy of the last.
|
|
6205
|
+
*/
|
|
6206
|
+
function isDuplicationCandidate(path) {
|
|
6207
|
+
return !isTestPath(path) && !isMigrationPath(path);
|
|
6208
|
+
}
|
|
6191
6209
|
async function copySources(request, paths, root) {
|
|
6192
6210
|
for (let start = 0; start < paths.length; start += SCAN_BATCH_FILES) {
|
|
6193
6211
|
const batch = paths.slice(start, start + SCAN_BATCH_FILES);
|
|
@@ -6266,7 +6284,7 @@ const BUILT_IN_RULES = [
|
|
|
6266
6284
|
pathRule("path.auth", RiskSeverity.Medium, new RegExp(`${SEGMENT}(auth|authn|authz|login|session|sessions|oauth|sso|permissions?|acl|rbac|access[_-]?control)${END}`, "i"), "Authentication or authorization", "A mistake here can let users act as someone else or reach data they should not."),
|
|
6267
6285
|
pathRule("path.crypto", RiskSeverity.Medium, new RegExp(`${SEGMENT}(crypto|cryptography|encrypt|encryption|cipher|signing|signature|jwt|keys?tore)${END}`, "i"), "Cryptography", "Subtle errors in cryptographic code rarely show in tests; check algorithms, key handling and randomness."),
|
|
6268
6286
|
pathRule("path.payments", RiskSeverity.Medium, new RegExp(`${SEGMENT}(payments?|billing|invoices?|stripe)${END}`, "i"), "Payments or billing", "Errors here cost money directly; check amounts, currencies and idempotency."),
|
|
6269
|
-
pathRule("path.migration", RiskSeverity.Medium,
|
|
6287
|
+
pathRule("path.migration", RiskSeverity.Medium, MIGRATION_PATH, "Database migration", "Migrations change production data and can be slow or irreversible; check locking and rollback."),
|
|
6270
6288
|
pathRule("path.infrastructure", RiskSeverity.Low, /\.tf$|(^|\/)Dockerfile[^/]*$|(^|\/)docker-compose[^/]*\.ya?ml$|(^|\/)(k8s|kubernetes|helm|charts)\//, "Infrastructure or deployment", "Changes the environment the code runs in: exposure, permissions and resource limits.")
|
|
6271
6289
|
];
|
|
6272
6290
|
/** One finding per file: team rules from the config first, then the first built-in rule that matches. */
|
|
@@ -9119,6 +9137,7 @@ Options:
|
|
|
9119
9137
|
--report <dir> With comment: the directory review wrote (--out)
|
|
9120
9138
|
--report-url <url> With comment: where reviewers can open the report
|
|
9121
9139
|
-h, --help Show this help
|
|
9140
|
+
-v, --version Show which Walkdiff this is
|
|
9122
9141
|
|
|
9123
9142
|
Environment:
|
|
9124
9143
|
GITHUB_TOKEN, GH_TOKEN Token for GitHub (required for private repositories)
|
|
@@ -9172,10 +9191,16 @@ function parseCommand(argv) {
|
|
|
9172
9191
|
type: "boolean",
|
|
9173
9192
|
short: "h",
|
|
9174
9193
|
default: false
|
|
9194
|
+
},
|
|
9195
|
+
version: {
|
|
9196
|
+
type: "boolean",
|
|
9197
|
+
short: "v",
|
|
9198
|
+
default: false
|
|
9175
9199
|
}
|
|
9176
9200
|
}
|
|
9177
9201
|
});
|
|
9178
9202
|
const [command, url, ...extra] = positionals;
|
|
9203
|
+
if (values.version) return { kind: "version" };
|
|
9179
9204
|
if (values.help || command === void 0) return { kind: "help" };
|
|
9180
9205
|
if (command === "setup") {
|
|
9181
9206
|
if (url !== void 0) throw new UsageError(`Unexpected arguments: ${[url, ...extra].join(" ")}`);
|
|
@@ -10556,6 +10581,13 @@ async function runComment(options, deps) {
|
|
|
10556
10581
|
deps.log(`Could not post the summary comment (this token may be read-only): ${error.message}`);
|
|
10557
10582
|
}
|
|
10558
10583
|
}
|
|
10584
|
+
// packages/cli/src/version.ts
|
|
10585
|
+
const MANIFEST_PATH = firstExisting([resolve(import.meta.dirname, "package.json"), resolve(import.meta.dirname, "../../../package.json")]);
|
|
10586
|
+
const manifestSchema = z.object({ version: z.string().min(1) });
|
|
10587
|
+
/** The running Walkdiff's version, read from its package.json. */
|
|
10588
|
+
function walkdiffVersion(manifestPath = MANIFEST_PATH) {
|
|
10589
|
+
return manifestSchema.parse(JSON.parse(readFileSync(manifestPath, "utf8"))).version;
|
|
10590
|
+
}
|
|
10559
10591
|
// packages/cli/src/main.ts
|
|
10560
10592
|
const EXIT_FAILURE = 1;
|
|
10561
10593
|
const EXIT_USAGE = 2;
|
|
@@ -10568,6 +10600,9 @@ async function main(argv) {
|
|
|
10568
10600
|
case "help":
|
|
10569
10601
|
console.log(USAGE);
|
|
10570
10602
|
return;
|
|
10603
|
+
case "version":
|
|
10604
|
+
console.log(`walkdiff ${walkdiffVersion()}`);
|
|
10605
|
+
return;
|
|
10571
10606
|
case "setup":
|
|
10572
10607
|
await installScannersHere((message) => console.error(message));
|
|
10573
10608
|
console.error(`Scanners are ready in ${MANAGED_SCANNERS_ROOT}.`);
|
|
@@ -10607,6 +10642,15 @@ main(process.argv.slice(2)).catch((error) => {
|
|
|
10607
10642
|
return;
|
|
10608
10643
|
}
|
|
10609
10644
|
console.error(error instanceof Error ? `${error.name}: ${error.message}` : String(error));
|
|
10645
|
+
console.error(versionLine());
|
|
10610
10646
|
process.exitCode = EXIT_FAILURE;
|
|
10611
10647
|
});
|
|
10648
|
+
/** Names the version in every failure, so a report of one says which Walkdiff it came from. */
|
|
10649
|
+
function versionLine() {
|
|
10650
|
+
try {
|
|
10651
|
+
return `(walkdiff ${walkdiffVersion()})`;
|
|
10652
|
+
} catch {
|
|
10653
|
+
return "(walkdiff, version unknown)";
|
|
10654
|
+
}
|
|
10655
|
+
}
|
|
10612
10656
|
export {};
|