Skip to content

Commit cff07bc

Browse files
authored
[code-genetics] test: add the origin test data set #1928 (#2278)
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 800e977 commit cff07bc

30 files changed

Lines changed: 5733 additions & 1 deletion

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ exclude-newer-package = { certifi = "2026-10-21T00:00:00Z", uv = "2026-10-21T00:
192192

193193
[tool.ruff]
194194
line-length = 88
195-
extend-exclude = ["migrations", "var"]
195+
extend-exclude = ["migrations", "var", "scanpipe/tests/data/code-genetics"]
196196
target-version = "py310"
197197

198198
[tool.ruff.lint]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Code Genetics origin test data set
2+
3+
Small synthetic codebases, one origin case each, to measure origin detection and determination. The ground truth is known by construction: every third-party file was taken from the official release artifact at its `download_url`.
4+
5+
| Case | Content | Expected origin |
6+
|---|---|---|
7+
| `exact-copy` | Unmodified `six.py` vendored in an application | `pkg:pypi/six@1.17.0` |
8+
| `vendored-copy` | `six.py` copied from urllib3, which vendors six reformatted with black | `pkg:pypi/six@1.16.0`, copied from `pkg:pypi/urllib3@1.26.20` |
9+
| `modified-copy` | inih with a local patch: `ini.h` unchanged, `ini.c` with changed lines and an added function | `pkg:github/benhoyt/inih@r62` |
10+
| `snippet` | lodash `debounce` function copied into an application file | `pkg:npm/lodash@4.17.21` |
11+
| `embedded-package` | Complete ms npm package in a vendor directory | `pkg:npm/ms@2.1.3` |
12+
| `no-origin` | Original application code | None |
13+
14+
## Layout
15+
16+
Each case directory contains:
17+
18+
- `codebase/`: the input to scan. It only contains the case files, without `.ABOUT` or other provenance files, as they would be detected by the scanners.
19+
- `expected.json`: the ground truth.
20+
- `matchcode-results.json`: the MatchCode.io match results, reduced to the fields used by the importer.
21+
- `scanoss-results.json`: the SCANOSS raw results, with paths relative to `codebase/`.
22+
23+
## expected.json
24+
25+
- `resources`: one entry per file of `codebase/`.
26+
- `path`: path relative to `codebase/`.
27+
- `match_type`: `exact`, `modified`, `snippet` or `none`, compared to the origin file.
28+
- `origin`: the original file (`purl`, `download_url`, `path` inside the downloaded archive, `sha1`), or `null` when there is no origin.
29+
- `copied_from`: the file actually copied, when it differs from the origin (vendored copy of a vendored copy).
30+
- `line_ranges`: for `modified` and `snippet` only, the `lines` of the codebase file that come from the `origin_lines` of the origin file. Ranges are inclusive.
31+
- `packages`: complete packages embedded in the codebase, with their directory `path`.
32+
33+
## Tool results
34+
35+
The tool results are real outputs, not handwritten:
36+
37+
- MatchCode.io results come from a local PurlDB indexing only the six reference packages of this data set (`pkg:pypi/six@1.16.0`, `pkg:pypi/six@1.17.0`, `pkg:pypi/urllib3@1.26.20`, `pkg:github/benhoyt/inih@r62`, `pkg:npm/lodash@4.17.21`, `pkg:npm/ms@2.1.3`), with the file and directory fingerprints computed by ScanCode.io.
38+
- SCANOSS results come from the free osskb.org service (knowledge base 26.10.19), which reports a single best match per file.
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/**
2+
* Helpers.
3+
*/
4+
5+
var s = 1000;
6+
var m = s * 60;
7+
var h = m * 60;
8+
var d = h * 24;
9+
var w = d * 7;
10+
var y = d * 365.25;
11+
12+
/**
13+
* Parse or format the given `val`.
14+
*
15+
* Options:
16+
*
17+
* - `long` verbose formatting [false]
18+
*
19+
* @param {String|Number} val
20+
* @param {Object} [options]
21+
* @throws {Error} throw an error if val is not a non-empty string or a number
22+
* @return {String|Number}
23+
* @api public
24+
*/
25+
26+
module.exports = function (val, options) {
27+
options = options || {};
28+
var type = typeof val;
29+
if (type === 'string' && val.length > 0) {
30+
return parse(val);
31+
} else if (type === 'number' && isFinite(val)) {
32+
return options.long ? fmtLong(val) : fmtShort(val);
33+
}
34+
throw new Error(
35+
'val is not a non-empty string or a valid number. val=' +
36+
JSON.stringify(val)
37+
);
38+
};
39+
40+
/**
41+
* Parse the given `str` and return milliseconds.
42+
*
43+
* @param {String} str
44+
* @return {Number}
45+
* @api private
46+
*/
47+
48+
function parse(str) {
49+
str = String(str);
50+
if (str.length > 100) {
51+
return;
52+
}
53+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
54+
str
55+
);
56+
if (!match) {
57+
return;
58+
}
59+
var n = parseFloat(match[1]);
60+
var type = (match[2] || 'ms').toLowerCase();
61+
switch (type) {
62+
case 'years':
63+
case 'year':
64+
case 'yrs':
65+
case 'yr':
66+
case 'y':
67+
return n * y;
68+
case 'weeks':
69+
case 'week':
70+
case 'w':
71+
return n * w;
72+
case 'days':
73+
case 'day':
74+
case 'd':
75+
return n * d;
76+
case 'hours':
77+
case 'hour':
78+
case 'hrs':
79+
case 'hr':
80+
case 'h':
81+
return n * h;
82+
case 'minutes':
83+
case 'minute':
84+
case 'mins':
85+
case 'min':
86+
case 'm':
87+
return n * m;
88+
case 'seconds':
89+
case 'second':
90+
case 'secs':
91+
case 'sec':
92+
case 's':
93+
return n * s;
94+
case 'milliseconds':
95+
case 'millisecond':
96+
case 'msecs':
97+
case 'msec':
98+
case 'ms':
99+
return n;
100+
default:
101+
return undefined;
102+
}
103+
}
104+
105+
/**
106+
* Short format for `ms`.
107+
*
108+
* @param {Number} ms
109+
* @return {String}
110+
* @api private
111+
*/
112+
113+
function fmtShort(ms) {
114+
var msAbs = Math.abs(ms);
115+
if (msAbs >= d) {
116+
return Math.round(ms / d) + 'd';
117+
}
118+
if (msAbs >= h) {
119+
return Math.round(ms / h) + 'h';
120+
}
121+
if (msAbs >= m) {
122+
return Math.round(ms / m) + 'm';
123+
}
124+
if (msAbs >= s) {
125+
return Math.round(ms / s) + 's';
126+
}
127+
return ms + 'ms';
128+
}
129+
130+
/**
131+
* Long format for `ms`.
132+
*
133+
* @param {Number} ms
134+
* @return {String}
135+
* @api private
136+
*/
137+
138+
function fmtLong(ms) {
139+
var msAbs = Math.abs(ms);
140+
if (msAbs >= d) {
141+
return plural(ms, msAbs, d, 'day');
142+
}
143+
if (msAbs >= h) {
144+
return plural(ms, msAbs, h, 'hour');
145+
}
146+
if (msAbs >= m) {
147+
return plural(ms, msAbs, m, 'minute');
148+
}
149+
if (msAbs >= s) {
150+
return plural(ms, msAbs, s, 'second');
151+
}
152+
return ms + ' ms';
153+
}
154+
155+
/**
156+
* Pluralization helper.
157+
*/
158+
159+
function plural(ms, msAbs, n, name) {
160+
var isPlural = msAbs >= n * 1.5;
161+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
162+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Vercel, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "ms",
3+
"version": "2.1.3",
4+
"description": "Tiny millisecond conversion utility",
5+
"repository": "vercel/ms",
6+
"main": "./index",
7+
"files": [
8+
"index.js"
9+
],
10+
"scripts": {
11+
"precommit": "lint-staged",
12+
"lint": "eslint lib/* bin/*",
13+
"test": "mocha tests.js"
14+
},
15+
"eslintConfig": {
16+
"extends": "eslint:recommended",
17+
"env": {
18+
"node": true,
19+
"es6": true
20+
}
21+
},
22+
"lint-staged": {
23+
"*.js": [
24+
"npm run lint",
25+
"prettier --single-quote --write",
26+
"git add"
27+
]
28+
},
29+
"license": "MIT",
30+
"devDependencies": {
31+
"eslint": "4.18.2",
32+
"expect.js": "0.3.1",
33+
"husky": "0.14.3",
34+
"lint-staged": "5.0.0",
35+
"mocha": "4.0.1",
36+
"prettier": "2.0.5"
37+
}
38+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# ms
2+
3+
![CI](https://github.com/vercel/ms/workflows/CI/badge.svg)
4+
5+
Use this package to easily convert various time formats to milliseconds.
6+
7+
## Examples
8+
9+
```js
10+
ms('2 days') // 172800000
11+
ms('1d') // 86400000
12+
ms('10h') // 36000000
13+
ms('2.5 hrs') // 9000000
14+
ms('2h') // 7200000
15+
ms('1m') // 60000
16+
ms('5s') // 5000
17+
ms('1y') // 31557600000
18+
ms('100') // 100
19+
ms('-3 days') // -259200000
20+
ms('-1h') // -3600000
21+
ms('-200') // -200
22+
```
23+
24+
### Convert from Milliseconds
25+
26+
```js
27+
ms(60000) // "1m"
28+
ms(2 * 60000) // "2m"
29+
ms(-3 * 60000) // "-3m"
30+
ms(ms('10 hours')) // "10h"
31+
```
32+
33+
### Time Format Written-Out
34+
35+
```js
36+
ms(60000, { long: true }) // "1 minute"
37+
ms(2 * 60000, { long: true }) // "2 minutes"
38+
ms(-3 * 60000, { long: true }) // "-3 minutes"
39+
ms(ms('10 hours'), { long: true }) // "10 hours"
40+
```
41+
42+
## Features
43+
44+
- Works both in [Node.js](https://nodejs.org) and in the browser
45+
- If a number is supplied to `ms`, a string with a unit is returned
46+
- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`)
47+
- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
48+
49+
## Related Packages
50+
51+
- [ms.macro](https://github.com/knpwrs/ms.macro) - Run `ms` as a macro at build-time.
52+
53+
## Caught a Bug?
54+
55+
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device
56+
2. Link the package to the global module directory: `npm link`
57+
3. Within the module you want to test your local development instance of ms, just link it to the dependencies: `npm link ms`. Instead of the default one from npm, Node.js will now use your clone of ms!
58+
59+
As always, you can run the tests using: `npm test`
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"description": "The complete ms npm package embedded in a vendor directory.",
3+
"packages": [
4+
{
5+
"path": "vendor/ms",
6+
"purl": "pkg:npm/ms@2.1.3",
7+
"download_url": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz"
8+
}
9+
],
10+
"resources": [
11+
{
12+
"path": "vendor/ms/index.js",
13+
"match_type": "exact",
14+
"origin": {
15+
"purl": "pkg:npm/ms@2.1.3",
16+
"download_url": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
17+
"path": "package/index.js",
18+
"sha1": "ea869663486f513cc4d1ca8312ed52a165c417fa"
19+
}
20+
},
21+
{
22+
"path": "vendor/ms/license.md",
23+
"match_type": "exact",
24+
"origin": {
25+
"purl": "pkg:npm/ms@2.1.3",
26+
"download_url": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
27+
"path": "package/license.md",
28+
"sha1": "ac646ea4ec65cd1feac459a194a15a52d147bdcf"
29+
}
30+
},
31+
{
32+
"path": "vendor/ms/package.json",
33+
"match_type": "exact",
34+
"origin": {
35+
"purl": "pkg:npm/ms@2.1.3",
36+
"download_url": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
37+
"path": "package/package.json",
38+
"sha1": "c290eb97736177176d071da4ac855ab995685c97"
39+
}
40+
},
41+
{
42+
"path": "vendor/ms/readme.md",
43+
"match_type": "exact",
44+
"origin": {
45+
"purl": "pkg:npm/ms@2.1.3",
46+
"download_url": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
47+
"path": "package/readme.md",
48+
"sha1": "e5af6580facbf96aac53741846d5845ca716ff97"
49+
}
50+
}
51+
]
52+
}

0 commit comments

Comments
 (0)