Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

test: limit web diff coverage to current push range (#33523)

Coding On Star0d72d9926364
diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml
index 4f00a9101c3..a19cb50abc7 100644
--- a/.github/workflows/main-ci.yml
+++ b/.github/workflows/main-ci.yml
@@ -63,8 +63,9 @@ jobs:
if: needs.check-changes.outputs.web-changed == 'true'
uses: ./.github/workflows/web-tests.yml
with:
- base_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
- head_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
+ base_sha: ${{ github.event.before || github.event.pull_request.base.sha }}
+ diff_range_mode: ${{ github.event.before && 'exact' || 'merge-base' }}
+ head_sha: ${{ github.event.after || github.event.pull_request.head.sha || github.sha }}
style-check:
name: Style Check
diff --git a/.github/workflows/web-tests.yml b/.github/workflows/web-tests.yml
index 443a22ea931..fb85d6e175d 100644
--- a/.github/workflows/web-tests.yml
+++ b/.github/workflows/web-tests.yml
@@ -6,6 +6,9 @@ on:
base_sha:
required: false
type: string
+ diff_range_mode:
+ required: false
+ type: string
head_sha:
required: false
type: string
@@ -89,6 +92,7 @@ jobs:
- name: Check app/components diff coverage
env:
BASE_SHA: ${{ inputs.base_sha }}
+ DIFF_RANGE_MODE: ${{ inputs.diff_range_mode }}
HEAD_SHA: ${{ inputs.head_sha }}
run: node ./scripts/check-components-diff-coverage.mjs
diff --git a/web/__tests__/check-components-diff-coverage.test.ts b/web/__tests__/check-components-diff-coverage.test.ts
index 9ce8b30ceb4..79f6c8fd266 100644
--- a/web/__tests__/check-components-diff-coverage.test.ts
+++ b/web/__tests__/check-components-diff-coverage.test.ts
@@ -1,4 +1,5 @@
import {
+ buildGitDiffRevisionArgs,
getChangedBranchCoverage,
getChangedStatementCoverage,
getIgnoredChangedLinesFromSource,
@@ -7,6 +8,11 @@ import {
} from '../scripts/check-components-diff-coverage-lib.mjs'
describe('check-components-diff-coverage helpers', () => {
+ it('should build exact and merge-base git diff revision args', () => {
+ expect(buildGitDiffRevisionArgs('base-sha', 'head-sha', 'exact')).toEqual(['base-sha', 'head-sha'])
+ expect(buildGitDiffRevisionArgs('base-sha', 'head-sha')).toEqual(['base-sha...head-sha'])
+ })
+
it('should parse changed line maps from unified diffs', () => {
const diff = [
'diff --git a/web/app/components/share/a.ts b/web/app/components/share/a.ts',
diff --git a/web/scripts/check-components-diff-coverage-lib.mjs b/web/scripts/check-components-diff-coverage-lib.mjs
index 56318f38a2a..48abc146130 100644
--- a/web/scripts/check-components-diff-coverage-lib.mjs
+++ b/web/scripts/check-components-diff-coverage-lib.mjs
@@ -3,6 +3,12 @@ import path from 'node:path'
const DIFF_COVERAGE_IGNORE_LINE_TOKEN = 'diff-coverage-ignore-line:'
+export function buildGitDiffRevisionArgs(base, head, mode = 'merge-base') {
+ return mode === 'exact'
+ ? [base, head]
+ : [`${base}...${head}`]
+}
+
export function parseChangedLineMap(diff, isTrackedComponentSourceFile) {
const lineMap = new Map()
let currentFile = null
diff --git a/web/scripts/check-components-diff-coverage.mjs b/web/scripts/check-components-diff-coverage.mjs
index 6a861c4f525..8cf3c962237 100644
--- a/web/scripts/check-components-diff-coverage.mjs
+++ b/web/scripts/check-components-diff-coverage.mjs
@@ -2,6 +2,7 @@ import { execFileSync } from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
import {
+ buildGitDiffRevisionArgs,
getChangedBranchCoverage,
getChangedStatementCoverage,
getIgnoredChangedLinesFromFile,
@@ -24,6 +25,7 @@ const APP_COMPONENTS_COVERAGE_PREFIX = 'app/components/'
const SHARED_TEST_PREFIX = 'web/__tests__/'
const STRICT_TEST_FILE_TOUCH = process.env.STRICT_COMPONENT_TEST_TOUCH === 'true'
const EXCLUDED_MODULES_LABEL = [...EXCLUDED_COMPONENT_MODULES].sort().join(', ')
+const DIFF_RANGE_MODE = process.env.DIFF_RANGE_MODE === 'exact' ? 'exact' : 'merge-base'
const repoRoot = repoRootFromCwd()
const webRoot = path.join(repoRoot, 'web')
@@ -216,6 +218,7 @@ function buildSummary({
'### app/components Diff Coverage',
'',
`Compared \`${baseSha.slice(0, 12)}\` -> \`${headSha.slice(0, 12)}\``,
+ `Diff range mode: \`${DIFF_RANGE_MODE}\``,
'',
`Excluded modules: \`${EXCLUDED_MODULES_LABEL}\``,
`Excluded file kinds: \`${COMPONENT_COVERAGE_EXCLUDE_LABEL}\``,
@@ -365,7 +368,7 @@ function buildSkipSummary(changedExcludedSourceFiles) {
}
function getChangedFiles(base, head) {
- const output = execGit(['diff', '--name-only', '--diff-filter=ACMR', `${base}...${head}`, '--', 'web/app/components', 'web/__tests__'])
+ const output = execGit(['diff', '--name-only', '--diff-filter=ACMR', ...buildGitDiffRevisionArgs(base, head, DIFF_RANGE_MODE), '--', 'web/app/components', 'web/__tests__'])
return output
.split('\n')
.map(line => line.trim())
@@ -373,7 +376,7 @@ function getChangedFiles(base, head) {
}
function getChangedLineMap(base, head) {
- const diff = execGit(['diff', '--unified=0', '--no-color', '--diff-filter=ACMR', `${base}...${head}`, '--', 'web/app/components'])
+ const diff = execGit(['diff', '--unified=0', '--no-color', '--diff-filter=ACMR', ...buildGitDiffRevisionArgs(base, head, DIFF_RANGE_MODE), '--', 'web/app/components'])
return parseChangedLineMap(diff, isTrackedComponentSourceFile)
}