@1aboveio/risk-compliance-skills 0.1.7 → 0.1.9
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/package.json +2 -2
- package/skills/compliance-audit/SKILL.md +1 -1
- package/skills/compliance-audit/release-check.mjs +3 -1
- package/skills/contract-compare/SKILL.md +1 -1
- package/skills/contract-compare/release-check.mjs +3 -1
- package/skills/contract-review/SKILL.md +1 -1
- package/skills/contract-review/release-check.mjs +3 -1
- package/skills/doc-authenticity/SKILL.md +1 -1
- package/skills/doc-authenticity/release-check.mjs +3 -1
- package/skills/fraud-analysis/SKILL.md +1 -1
- package/skills/fraud-analysis/release-check.mjs +3 -1
- package/skills/payment-analysis/SKILL.md +1 -1
- package/skills/payment-analysis/release-check.mjs +3 -1
- package/skills/similar-domain/SKILL.md +1 -1
- package/skills/similar-domain/release-check.mjs +3 -1
- package/skills/tld-detection/SKILL.md +1 -1
- package/skills/tld-detection/release-check.mjs +3 -1
- package/skills/compliance-audit/scripts/compliance-audit.test.mjs +0 -14
- package/skills/doc-authenticity/manual-invocation.test.mjs +0 -12
- package/skills/doc-authenticity/scripts/validate_verdict.test.mjs +0 -212
- package/skills/tld-detection/scripts/detect_ladders.test.mjs +0 -14
- package/skills/tld-detection/scripts/detect_streams.test.mjs +0 -14
- package/skills/tld-detection/tests/test_detect_ladders.py +0 -134
- package/skills/tld-detection/tests/test_detect_streams.py +0 -520
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1aboveio/risk-compliance-skills",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Compliance audits, contract review, payment and fraud analysis.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"house-style",
|
|
37
37
|
"polish-cn"
|
|
38
38
|
],
|
|
39
|
-
"digest": "
|
|
39
|
+
"digest": "70fed43fda7c72625770e42f699ee65405c17ea4d81c9c4cc669f337c34a3e0b"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: compliance-audit
|
|
3
3
|
version: 2.9.0
|
|
4
4
|
description: "Audit operations against financial-compliance checklists (AML/KYC, VARS, PCI-DSS, TPA oversight, onboarding, transaction monitoring). Produces tracker.md (with a tracker.xlsx export) and phase-trail.md with layered validation; cites evidence by original filename. Input: reg-parser or the built-in VARS checklist."
|
|
5
|
-
release-version: 0.
|
|
5
|
+
release-version: 0.44.0
|
|
6
6
|
---
|
|
7
7
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
8
8
|
# Compliance Audit
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: contract-compare
|
|
3
3
|
description: "Compare two or more contracts side-by-side for structured diff, gap analysis, and benchmarking. Use when: comparing contracts or agreements, contract diff, compare terms, vendor-vs-vendor, compare our template vs theirs, compliance gap between contracts. NOT for single-contract risk review — use contract-review for that."
|
|
4
|
-
release-version: 0.
|
|
4
|
+
release-version: 0.44.0
|
|
5
5
|
---
|
|
6
6
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
7
7
|
# Contract Compare
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: contract-review
|
|
3
3
|
description: "Review contracts for legal, commercial, and compliance risks via convert → chunk review → merge → validate (+ optional mandate preprocessing). Use for reviewing, auditing, or checking any contract, agreement, NDA, MSA, or SLA; input a file path (PDF/DOCX/TXT) or pasted text."
|
|
4
|
-
release-version: 0.
|
|
4
|
+
release-version: 0.44.0
|
|
5
5
|
---
|
|
6
6
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
7
7
|
# Contract Review
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -3,7 +3,7 @@ name: doc-authenticity
|
|
|
3
3
|
version: 0.4.1
|
|
4
4
|
description: "Screen PDF documents and raster images for fabrication, tampering, Photoshop or other image-editor use, and content validity. Detects file type, runs format-specific authenticity forensics, classifies bank statements, conversation logs, invoices, agreements, and other documents, then applies type-specific validity checks. Produces separate authenticity (NO_EVIDENCE_OF_MODIFICATION / SUSPICIOUS / LIKELY_MODIFIED / INCONCLUSIVE) and validity (VALID / INVALID / INCONCLUSIVE) verdicts. Use whenever a user asks whether a document, screenshot, scan, statement, invoice, contract, chat log, receipt, or payment evidence is genuine, original, edited, Photoshopped, manipulated, fake, or valid."
|
|
5
5
|
disable-model-invocation: true
|
|
6
|
-
release-version: 0.
|
|
6
|
+
release-version: 0.44.0
|
|
7
7
|
---
|
|
8
8
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
9
9
|
# Document and Image Authenticity
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -10,7 +10,7 @@ description: >
|
|
|
10
10
|
impact, and a business report. Use for fraud, scam, mule, account-takeover,
|
|
11
11
|
chargeback, dispute, transfer, collection, or payout risk analysis even when the
|
|
12
12
|
user does not name this skill.
|
|
13
|
-
release-version: 0.
|
|
13
|
+
release-version: 0.44.0
|
|
14
14
|
---
|
|
15
15
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
16
16
|
# Fraud Analysis
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -14,7 +14,7 @@ description: >
|
|
|
14
14
|
transactions" — even if they do not say payment-analysis. Do NOT use for
|
|
15
15
|
supervised fraud-rule mining (fraud-analysis) or TLD / MCC-miscoding
|
|
16
16
|
clusters (tld-detection).
|
|
17
|
-
release-version: 0.
|
|
17
|
+
release-version: 0.44.0
|
|
18
18
|
---
|
|
19
19
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
20
20
|
# Payment Analysis
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -8,7 +8,7 @@ description: >
|
|
|
8
8
|
links, an entity chain, and a watchlist for the operator's next domains.
|
|
9
9
|
Not transaction data (tld-detection) or fraud rules (fraud-analysis).
|
|
10
10
|
disable-model-invocation: true
|
|
11
|
-
release-version: 0.
|
|
11
|
+
release-version: 0.44.0
|
|
12
12
|
---
|
|
13
13
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
14
14
|
# Similar Domain
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -11,7 +11,7 @@ description: >
|
|
|
11
11
|
with a ≤3-sentence summary.
|
|
12
12
|
Not payment-analysis, fraud-analysis, or website research (similar-domain).
|
|
13
13
|
disable-model-invocation: true
|
|
14
|
-
release-version: 0.
|
|
14
|
+
release-version: 0.44.0
|
|
15
15
|
---
|
|
16
16
|
**Updates:** Once/session run `node <skill-base-dir>/release-check.mjs`.
|
|
17
17
|
# TLD Detection
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -46,6 +46,8 @@ function writeCache(path, value) {
|
|
|
46
46
|
|
|
47
47
|
function main(now = Date.now()) {
|
|
48
48
|
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const bundle = readJson(join(resolve(here, '../../..'), 'package.json'));
|
|
50
|
+
if (bundle.name === '@1aboveio/skills' && bundle.nativeCodex?.schemaVersion === 1) return;
|
|
49
51
|
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
52
|
const name = frontmatterValue(skill, 'name');
|
|
51
53
|
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import test from 'node:test';
|
|
6
|
-
|
|
7
|
-
const scriptsDir = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
|
|
9
|
-
for (const suite of ['test_validate_tracker.py', 'test_export_tracker_xlsx.py']) {
|
|
10
|
-
test(`compliance-audit ${suite}`, () => {
|
|
11
|
-
const result = spawnSync('python3', [join(scriptsDir, suite)], { encoding: 'utf8' });
|
|
12
|
-
assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { dirname } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
|
|
6
|
-
import { manualOnlyPolicyFindings } from '../../engineering/engineering-runtime/scripts/invocation-policy.mjs';
|
|
7
|
-
|
|
8
|
-
const SKILL_ROOT = dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
|
|
10
|
-
test('doc-authenticity remains explicit-invocation only across supported harnesses', () => {
|
|
11
|
-
assert.deepEqual(manualOnlyPolicyFindings(SKILL_ROOT), []);
|
|
12
|
-
});
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
// @covers doc-authenticity:routed-verdict-contract
|
|
2
|
-
// @level integration
|
|
3
|
-
import assert from 'node:assert/strict';
|
|
4
|
-
import { spawnSync } from 'node:child_process';
|
|
5
|
-
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
6
|
-
import { tmpdir } from 'node:os';
|
|
7
|
-
import { dirname, join } from 'node:path';
|
|
8
|
-
import { test } from 'node:test';
|
|
9
|
-
import { fileURLToPath } from 'node:url';
|
|
10
|
-
|
|
11
|
-
const SCRIPTS = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const VALIDATOR = join(SCRIPTS, 'validate_verdict.py');
|
|
13
|
-
const VALIDITY_IDS = {
|
|
14
|
-
bank_statement: [...Array.from({ length: 5 }, (_, i) => `C${i + 1}`), ...Array.from({ length: 5 }, (_, i) => `D${i + 1}`)],
|
|
15
|
-
invoice: Array.from({ length: 8 }, (_, i) => `N${i + 1}`),
|
|
16
|
-
agreement: Array.from({ length: 8 }, (_, i) => `A${i + 1}`),
|
|
17
|
-
conversation_log: [],
|
|
18
|
-
other: [],
|
|
19
|
-
};
|
|
20
|
-
const CONTENT_IDS = new Set([
|
|
21
|
-
...Array.from({ length: 5 }, (_, i) => `C${i + 1}`),
|
|
22
|
-
'N2', 'N3', 'N4', 'N7',
|
|
23
|
-
'A2', 'A4', 'A5', 'A7',
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
function check(id) {
|
|
27
|
-
const authenticity = id.startsWith('F') || id.startsWith('I');
|
|
28
|
-
return {
|
|
29
|
-
id,
|
|
30
|
-
name: `Check ${id}`,
|
|
31
|
-
axis: authenticity ? 'authenticity' : 'validity',
|
|
32
|
-
dimension: authenticity ? 'file_forensics' : CONTENT_IDS.has(id) ? 'content' : 'domain',
|
|
33
|
-
result: 'PASS',
|
|
34
|
-
decisive: false,
|
|
35
|
-
evidence: `Concrete evidence for ${id}.`,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function verdict(fileType, docType) {
|
|
40
|
-
const prefix = fileType === 'pdf' ? 'F' : 'I';
|
|
41
|
-
const authIds = Array.from({ length: 9 }, (_, i) => `${prefix}${i + 1}`);
|
|
42
|
-
const validityIds = VALIDITY_IDS[docType];
|
|
43
|
-
return {
|
|
44
|
-
schema_version: '2.2',
|
|
45
|
-
artifact: {
|
|
46
|
-
path: `/tmp/${fileType}-${docType}`,
|
|
47
|
-
file_type: fileType,
|
|
48
|
-
media_type: fileType === 'pdf' ? 'application/pdf' : 'image/jpeg',
|
|
49
|
-
size_bytes: 1234,
|
|
50
|
-
sha256: 'a'.repeat(64),
|
|
51
|
-
extension_magic_match: true,
|
|
52
|
-
doc_type: docType,
|
|
53
|
-
detail: 'route fixture',
|
|
54
|
-
claimed_issuer: null,
|
|
55
|
-
supplied_claim: 'Test document.',
|
|
56
|
-
},
|
|
57
|
-
authenticity: {
|
|
58
|
-
verdict: 'NO_EVIDENCE_OF_MODIFICATION',
|
|
59
|
-
confidence: 'MEDIUM',
|
|
60
|
-
summary: 'No modification evidence.',
|
|
61
|
-
},
|
|
62
|
-
validity: {
|
|
63
|
-
verdict: validityIds.length ? 'VALID' : 'INCONCLUSIVE',
|
|
64
|
-
confidence: 'LOW',
|
|
65
|
-
summary: 'Validity route result.',
|
|
66
|
-
},
|
|
67
|
-
checks: [...authIds, ...validityIds].map(check),
|
|
68
|
-
summary: 'Route test.',
|
|
69
|
-
checked_at: '2026-09-03T13:30:00+08:00',
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function runValidator(directory, name, value) {
|
|
74
|
-
const path = join(directory, `${name}.json`);
|
|
75
|
-
writeFileSync(path, `${JSON.stringify(value)}\n`);
|
|
76
|
-
return spawnSync('python3', [VALIDATOR, path], { encoding: 'utf8' });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
test('all file-type and document-type routes require the correct check set', () => {
|
|
80
|
-
const directory = mkdtempSync(join(tmpdir(), 'doc-auth-routes-'));
|
|
81
|
-
try {
|
|
82
|
-
for (const fileType of ['pdf', 'image']) {
|
|
83
|
-
for (const docType of Object.keys(VALIDITY_IDS)) {
|
|
84
|
-
const result = runValidator(directory, `${fileType}-${docType}`, verdict(fileType, docType));
|
|
85
|
-
assert.equal(result.status, 0, `${fileType}/${docType}: ${result.stdout}${result.stderr}`);
|
|
86
|
-
assert.match(result.stdout, new RegExp(`valid: ${fileType}/${docType} route`));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} finally {
|
|
90
|
-
rmSync(directory, { recursive: true, force: true });
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test('conversation logs and other documents cannot claim specialized validity', () => {
|
|
95
|
-
const directory = mkdtempSync(join(tmpdir(), 'doc-auth-no-validity-'));
|
|
96
|
-
try {
|
|
97
|
-
for (const docType of ['conversation_log', 'other']) {
|
|
98
|
-
const value = verdict('image', docType);
|
|
99
|
-
value.validity.verdict = 'VALID';
|
|
100
|
-
const result = runValidator(directory, docType, value);
|
|
101
|
-
assert.notEqual(result.status, 0);
|
|
102
|
-
assert.match(result.stdout, /validity verdict must be INCONCLUSIVE/);
|
|
103
|
-
}
|
|
104
|
-
} finally {
|
|
105
|
-
rmSync(directory, { recursive: true, force: true });
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('missing and cross-profile validity checks fail closed', () => {
|
|
110
|
-
const directory = mkdtempSync(join(tmpdir(), 'doc-auth-invalid-route-'));
|
|
111
|
-
try {
|
|
112
|
-
const missing = verdict('pdf', 'invoice');
|
|
113
|
-
missing.checks = missing.checks.filter(({ id }) => id !== 'N8');
|
|
114
|
-
const missingResult = runValidator(directory, 'missing-invoice-check', missing);
|
|
115
|
-
assert.notEqual(missingResult.status, 0);
|
|
116
|
-
assert.match(missingResult.stdout, /missing checks: \['N8'\]/);
|
|
117
|
-
|
|
118
|
-
const mixed = verdict('image', 'agreement');
|
|
119
|
-
mixed.checks.push(check('N1'));
|
|
120
|
-
const mixedResult = runValidator(directory, 'mixed-agreement-check', mixed);
|
|
121
|
-
assert.notEqual(mixedResult.status, 0);
|
|
122
|
-
assert.match(mixedResult.stdout, /checks do not belong to the selected route: \['N1'\]/);
|
|
123
|
-
} finally {
|
|
124
|
-
rmSync(directory, { recursive: true, force: true });
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test('artifact audit fields and checked_at timezone are mandatory', () => {
|
|
129
|
-
const directory = mkdtempSync(join(tmpdir(), 'doc-auth-artifact-'));
|
|
130
|
-
try {
|
|
131
|
-
const missingAudit = verdict('pdf', 'invoice');
|
|
132
|
-
delete missingAudit.artifact.sha256;
|
|
133
|
-
const missingResult = runValidator(directory, 'missing-hash', missingAudit);
|
|
134
|
-
assert.notEqual(missingResult.status, 0);
|
|
135
|
-
assert.match(missingResult.stdout, /artifact missing keys: \['sha256'\]/);
|
|
136
|
-
|
|
137
|
-
const badTimestamp = verdict('pdf', 'invoice');
|
|
138
|
-
badTimestamp.checked_at = '2026-99-99T13:30:00';
|
|
139
|
-
const timestampResult = runValidator(directory, 'bad-timestamp', badTimestamp);
|
|
140
|
-
assert.notEqual(timestampResult.status, 0);
|
|
141
|
-
assert.match(timestampResult.stdout, /valid ISO 8601 timestamp with timezone/);
|
|
142
|
-
} finally {
|
|
143
|
-
rmSync(directory, { recursive: true, force: true });
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('authenticity verdict must match decisive, FAIL, FLAG, and NA thresholds', () => {
|
|
148
|
-
const directory = mkdtempSync(join(tmpdir(), 'doc-auth-rubric-'));
|
|
149
|
-
try {
|
|
150
|
-
const tooManyFlags = verdict('pdf', 'other');
|
|
151
|
-
for (const id of ['F1', 'F2', 'F3']) tooManyFlags.checks.find((item) => item.id === id).result = 'FLAG';
|
|
152
|
-
const flagsResult = runValidator(directory, 'flags', tooManyFlags);
|
|
153
|
-
assert.notEqual(flagsResult.status, 0);
|
|
154
|
-
assert.match(flagsResult.stdout, /authenticity verdict must be SUSPICIOUS/);
|
|
155
|
-
|
|
156
|
-
const unavailable = verdict('pdf', 'other');
|
|
157
|
-
for (const id of ['F1', 'F2', 'F3', 'F4', 'F5']) unavailable.checks.find((item) => item.id === id).result = 'NA';
|
|
158
|
-
const unavailableResult = runValidator(directory, 'unavailable', unavailable);
|
|
159
|
-
assert.notEqual(unavailableResult.status, 0);
|
|
160
|
-
assert.match(unavailableResult.stdout, /authenticity verdict must be INCONCLUSIVE/);
|
|
161
|
-
|
|
162
|
-
const decisive = verdict('image', 'other');
|
|
163
|
-
decisive.authenticity.verdict = 'LIKELY_MODIFIED';
|
|
164
|
-
const splice = decisive.checks.find((item) => item.id === 'I7');
|
|
165
|
-
splice.result = 'FAIL';
|
|
166
|
-
splice.decisive = true;
|
|
167
|
-
const decisiveResult = runValidator(directory, 'decisive', decisive);
|
|
168
|
-
assert.equal(decisiveResult.status, 0, decisiveResult.stdout);
|
|
169
|
-
} finally {
|
|
170
|
-
rmSync(directory, { recursive: true, force: true });
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test('validity verdict must match decisive, FAIL, FLAG, and NA thresholds', () => {
|
|
175
|
-
const directory = mkdtempSync(join(tmpdir(), 'doc-validity-rubric-'));
|
|
176
|
-
try {
|
|
177
|
-
const unavailable = verdict('pdf', 'invoice');
|
|
178
|
-
unavailable.validity.verdict = 'INCONCLUSIVE';
|
|
179
|
-
for (const id of ['N1', 'N2', 'N3', 'N4']) unavailable.checks.find((item) => item.id === id).result = 'NA';
|
|
180
|
-
const unavailableResult = runValidator(directory, 'unavailable-validity', unavailable);
|
|
181
|
-
assert.equal(unavailableResult.status, 0, unavailableResult.stdout);
|
|
182
|
-
|
|
183
|
-
const decisive = verdict('pdf', 'agreement');
|
|
184
|
-
decisive.validity.verdict = 'INVALID';
|
|
185
|
-
const conflict = decisive.checks.find((item) => item.id === 'A4');
|
|
186
|
-
conflict.result = 'FAIL';
|
|
187
|
-
conflict.decisive = true;
|
|
188
|
-
const decisiveResult = runValidator(directory, 'decisive-validity', decisive);
|
|
189
|
-
assert.equal(decisiveResult.status, 0, decisiveResult.stdout);
|
|
190
|
-
|
|
191
|
-
const invalidDecisive = verdict('pdf', 'invoice');
|
|
192
|
-
invalidDecisive.checks.find((item) => item.id === 'N1').decisive = true;
|
|
193
|
-
const invalidResult = runValidator(directory, 'decisive-pass', invalidDecisive);
|
|
194
|
-
assert.notEqual(invalidResult.status, 0);
|
|
195
|
-
assert.match(invalidResult.stdout, /only a FAIL can be decisive/);
|
|
196
|
-
} finally {
|
|
197
|
-
rmSync(directory, { recursive: true, force: true });
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
test('the schema advertises every routed document type and check family', () => {
|
|
202
|
-
const schema = JSON.parse(readFileSync(join(SCRIPTS, '..', 'references', 'verdict.schema.json'), 'utf8'));
|
|
203
|
-
assert.deepEqual(
|
|
204
|
-
schema.properties.artifact.properties.doc_type.enum,
|
|
205
|
-
['bank_statement', 'conversation_log', 'invoice', 'agreement', 'other'],
|
|
206
|
-
);
|
|
207
|
-
assert.equal(schema.properties.schema_version.const, '2.2');
|
|
208
|
-
assert.ok(schema.properties.artifact.required.includes('sha256'));
|
|
209
|
-
assert.ok(schema.$defs.check.required.includes('decisive'));
|
|
210
|
-
assert.match(schema.$defs.check.properties.id.pattern, /N\[1-8\]/);
|
|
211
|
-
assert.match(schema.$defs.check.properties.id.pattern, /A\[1-8\]/);
|
|
212
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import test from 'node:test';
|
|
6
|
-
|
|
7
|
-
const skillDir = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
8
|
-
|
|
9
|
-
test('TLD ladder detector Python contract', () => {
|
|
10
|
-
const result = spawnSync('python3', [join(skillDir, 'tests', 'test_detect_ladders.py'), '-v'], {
|
|
11
|
-
encoding: 'utf8',
|
|
12
|
-
});
|
|
13
|
-
assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
|
|
14
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import test from 'node:test';
|
|
6
|
-
|
|
7
|
-
const skillDir = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
8
|
-
|
|
9
|
-
test('TLD stream inference Python contract', () => {
|
|
10
|
-
const result = spawnSync('python3', [join(skillDir, 'tests', 'test_detect_streams.py'), '-v'], {
|
|
11
|
-
encoding: 'utf8',
|
|
12
|
-
});
|
|
13
|
-
assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
|
|
14
|
-
});
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
from collections import Counter
|
|
2
|
-
import csv
|
|
3
|
-
from decimal import Decimal
|
|
4
|
-
import importlib.util
|
|
5
|
-
import json
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
import subprocess
|
|
8
|
-
import sys
|
|
9
|
-
import tempfile
|
|
10
|
-
import unittest
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
sys.dont_write_bytecode = True
|
|
14
|
-
SCRIPT = Path(__file__).parents[1] / "scripts" / "detect_ladders.py"
|
|
15
|
-
SPEC = importlib.util.spec_from_file_location("detect_ladders", SCRIPT)
|
|
16
|
-
MODULE = importlib.util.module_from_spec(SPEC)
|
|
17
|
-
assert SPEC.loader is not None
|
|
18
|
-
sys.modules[SPEC.name] = MODULE
|
|
19
|
-
SPEC.loader.exec_module(MODULE)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def pair(amount: str) -> tuple[str, Decimal]:
|
|
23
|
-
return "USD", Decimal(amount)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class DetectLaddersTest(unittest.TestCase):
|
|
27
|
-
def detect(self, values: dict[str, int], cap: str = "0.15"):
|
|
28
|
-
counts = Counter({pair(amount): count for amount, count in values.items()})
|
|
29
|
-
return MODULE.detect_ladders(
|
|
30
|
-
counts,
|
|
31
|
-
sum(counts.values()),
|
|
32
|
-
MODULE.LadderConfig({"USD": Decimal(cap)}),
|
|
33
|
-
)[0]
|
|
34
|
-
|
|
35
|
-
def test_detects_tight_exact_ladder(self):
|
|
36
|
-
ladders = self.detect({"28.03": 131, "56.04": 117, "112.09": 65, "224.19": 27, "70.00": 100})
|
|
37
|
-
amounts = {amount for _, amount in ladders[0]["pairs"]}
|
|
38
|
-
self.assertEqual(amounts, {Decimal("28.03"), Decimal("56.04"), Decimal("112.09"), Decimal("224.19")})
|
|
39
|
-
|
|
40
|
-
def test_keeps_multiple_exact_anchors_at_one_level(self):
|
|
41
|
-
ladders = self.detect({"14.41": 34, "14.52": 25, "28.94": 43, "57.96": 29, "80.00": 100})
|
|
42
|
-
levels = next(ladder["levels"] for ladder in ladders if pair("28.94") in ladder["pairs"])
|
|
43
|
-
self.assertEqual(levels[-1], {pair("14.41"), pair("14.52")})
|
|
44
|
-
|
|
45
|
-
def test_rejects_upper_amount_outside_absolute_cap(self):
|
|
46
|
-
ladders = self.detect({"14.41": 34, "28.94": 43, "57.96": 29, "116.85": 29, "80.00": 100})
|
|
47
|
-
ladder = next(ladder for ladder in ladders if pair("14.41") in ladder["pairs"])
|
|
48
|
-
self.assertNotIn(pair("116.85"), ladder["pairs"])
|
|
49
|
-
|
|
50
|
-
def test_requires_explicit_currency_cap(self):
|
|
51
|
-
with self.assertRaisesRegex(ValueError, "missing absolute residual cap"):
|
|
52
|
-
MODULE.detect_ladders(Counter({pair("10"): 10}), 10, MODULE.LadderConfig({}))
|
|
53
|
-
|
|
54
|
-
def test_ignores_currency_below_rung_pool_threshold(self):
|
|
55
|
-
counts = Counter({pair("10"): 1000, ("EUR", Decimal("9.99")): 1})
|
|
56
|
-
ladders, _ = MODULE.detect_ladders(counts, 1001, MODULE.LadderConfig({"USD": Decimal("0.15")}))
|
|
57
|
-
self.assertEqual(ladders, [])
|
|
58
|
-
|
|
59
|
-
def test_sensitivity_reports_coverage_by_cap(self):
|
|
60
|
-
counts = Counter({pair("14.41"): 34, pair("28.94"): 43, pair("57.96"): 29})
|
|
61
|
-
rows = MODULE.sensitivity_analysis(
|
|
62
|
-
counts,
|
|
63
|
-
sum(counts.values()),
|
|
64
|
-
MODULE.LadderConfig({"USD": Decimal("0.15")}),
|
|
65
|
-
"USD",
|
|
66
|
-
[Decimal("0.10"), Decimal("0.15")],
|
|
67
|
-
)
|
|
68
|
-
self.assertEqual([row["ladder_count"] for row in rows], [0, 1])
|
|
69
|
-
|
|
70
|
-
def test_keeps_below_threshold_family_out_of_clusters(self):
|
|
71
|
-
counts = Counter({pair("10"): 32, pair("20"): 32, pair("40"): 32})
|
|
72
|
-
ladders, metadata = MODULE.detect_ladders(
|
|
73
|
-
counts,
|
|
74
|
-
96,
|
|
75
|
-
MODULE.LadderConfig({"USD": Decimal("0.15")}),
|
|
76
|
-
)
|
|
77
|
-
self.assertEqual(ladders, [])
|
|
78
|
-
self.assertEqual(metadata["below_threshold"][0]["attempts"], 96)
|
|
79
|
-
|
|
80
|
-
def test_same_pair_can_belong_to_different_partitions(self):
|
|
81
|
-
entries = []
|
|
82
|
-
amounts = (("10", 40), ("20", 40), ("40", 40))
|
|
83
|
-
for partition in ("alpha", "beta"):
|
|
84
|
-
for amount, count in amounts:
|
|
85
|
-
entries.extend([(partition, pair(amount))] * count)
|
|
86
|
-
_, ladders, _ = MODULE.detect_partitioned_ladders(
|
|
87
|
-
entries,
|
|
88
|
-
MODULE.LadderConfig({"USD": Decimal("0.15")}),
|
|
89
|
-
)
|
|
90
|
-
self.assertEqual(len(ladders), 2)
|
|
91
|
-
self.assertEqual({ladder["partition"] for ladder in ladders}, {"alpha", "beta"})
|
|
92
|
-
|
|
93
|
-
def test_requires_at_least_three_levels(self):
|
|
94
|
-
self.assertEqual(self.detect({"10": 60, "20": 60, "70": 100}), [])
|
|
95
|
-
|
|
96
|
-
def test_rejects_non_two_x_relationships(self):
|
|
97
|
-
self.assertEqual(self.detect({"10": 40, "30": 40, "90": 40}), [])
|
|
98
|
-
|
|
99
|
-
def test_cli_keeps_whole_descriptor_despite_country_and_pattern_labels(self):
|
|
100
|
-
with tempfile.TemporaryDirectory() as directory:
|
|
101
|
-
csv_path = Path(directory) / "clean.csv"
|
|
102
|
-
with csv_path.open("w", encoding="utf-8", newline="") as handle:
|
|
103
|
-
writer = csv.DictWriter(handle, fieldnames=["descriptor", "country", "currency", "amount", "payment_pattern"])
|
|
104
|
-
writer.writeheader()
|
|
105
|
-
for country in ("US", "GB"):
|
|
106
|
-
for amount in ("10", "20", "40"):
|
|
107
|
-
writer.writerows(
|
|
108
|
-
{"descriptor": "ACME", "country": country, "currency": "USD", "amount": amount,
|
|
109
|
-
"payment_pattern": "Direct top-up pattern" if country == "US" else "E-commerce pattern"}
|
|
110
|
-
for _ in range(20)
|
|
111
|
-
)
|
|
112
|
-
result = subprocess.run(
|
|
113
|
-
[
|
|
114
|
-
sys.executable,
|
|
115
|
-
str(SCRIPT),
|
|
116
|
-
str(csv_path),
|
|
117
|
-
"--descriptor-column", "descriptor",
|
|
118
|
-
"--bin-country-column", "country",
|
|
119
|
-
"--currency-column", "currency",
|
|
120
|
-
"--amount-column", "amount",
|
|
121
|
-
"--cap", "USD=0.15",
|
|
122
|
-
],
|
|
123
|
-
check=True,
|
|
124
|
-
capture_output=True,
|
|
125
|
-
text=True,
|
|
126
|
-
)
|
|
127
|
-
payload = json.loads(result.stdout)
|
|
128
|
-
self.assertEqual(len(payload["ladders"]), 1)
|
|
129
|
-
self.assertEqual(payload["ladders"][0]["partition_attempts"], 120)
|
|
130
|
-
self.assertEqual(payload["ladders"][0]["bin_country_components"], {"US": 60, "GB": 60})
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if __name__ == "__main__":
|
|
134
|
-
unittest.main()
|
|
@@ -1,520 +0,0 @@
|
|
|
1
|
-
import csv
|
|
2
|
-
from copy import deepcopy
|
|
3
|
-
import importlib.util
|
|
4
|
-
import json
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
import random
|
|
7
|
-
import subprocess
|
|
8
|
-
import sys
|
|
9
|
-
import tempfile
|
|
10
|
-
from types import SimpleNamespace
|
|
11
|
-
import unittest
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
sys.dont_write_bytecode = True
|
|
15
|
-
SCRIPT = Path(__file__).parents[1] / "scripts" / "detect_streams.py"
|
|
16
|
-
SPEC = importlib.util.spec_from_file_location("detect_streams", SCRIPT)
|
|
17
|
-
MODULE = importlib.util.module_from_spec(SPEC)
|
|
18
|
-
assert SPEC.loader is not None
|
|
19
|
-
sys.modules[SPEC.name] = MODULE
|
|
20
|
-
SPEC.loader.exec_module(MODULE)
|
|
21
|
-
|
|
22
|
-
DAYS = [f"2026-08-{d:02d}" for d in range(1, 21)]
|
|
23
|
-
FIELDS = ["amount", "currency", "ts", "descriptor", "country", "response", "account", "card_type", "avs", "auth"]
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def rates_cache() -> dict:
|
|
27
|
-
"""USD base; EUR drifts 1.15 -> 1.17, AUD 0.70 -> 0.72 over the window (quoted as units per USD)."""
|
|
28
|
-
rates = {}
|
|
29
|
-
for i, day in enumerate(DAYS):
|
|
30
|
-
eur = 1.15 + 0.001 * i
|
|
31
|
-
aud = 0.70 + 0.001 * i
|
|
32
|
-
rates[day] = {"EUR": 1 / eur, "AUD": 1 / aud, "GBP": 1 / 1.34, "JPY": 147.0}
|
|
33
|
-
return {"base": "USD", "rates": rates}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def synthetic_rows() -> list[dict]:
|
|
37
|
-
rng = random.Random(3)
|
|
38
|
-
rates = rates_cache()["rates"]
|
|
39
|
-
rows = []
|
|
40
|
-
acc = 0
|
|
41
|
-
|
|
42
|
-
def row(amount, day, ctry, resp="A001", account=None, card="Debit", avs="Postal code not checked", auth="None", desc="HLP*shop", hour=None):
|
|
43
|
-
nonlocal acc
|
|
44
|
-
acc += 1
|
|
45
|
-
h = hour if hour is not None else rng.randint(0, 23)
|
|
46
|
-
return {"amount": f"{amount:.2f}", "currency": "USD", "ts": f"{day} {h:02d}:{rng.randint(0, 59):02d}:{rng.randint(0, 59):02d}",
|
|
47
|
-
"descriptor": desc, "country": ctry, "response": resp, "account": account or f"4{acc:05d}******{acc % 9999:04d}",
|
|
48
|
-
"card_type": card, "avs": avs, "auth": auth}
|
|
49
|
-
|
|
50
|
-
# Euro-wallet players (Germany): presets 10/20/50 at live rate with 0-1% markup, some retries
|
|
51
|
-
for _ in range(400):
|
|
52
|
-
day = rng.choice(DAYS)
|
|
53
|
-
preset = rng.choice([10, 10, 10, 20, 20, 50])
|
|
54
|
-
usd = preset / rates[day]["EUR"] * (1 + rng.uniform(0, 0.01))
|
|
55
|
-
rows.append(row(usd, day, "Germany", resp=rng.choice(["A001", "A001", "D102"])))
|
|
56
|
-
# Australian players: A$30 / A$50 live
|
|
57
|
-
for _ in range(300):
|
|
58
|
-
day = rng.choice(DAYS)
|
|
59
|
-
preset = rng.choice([30, 30, 50])
|
|
60
|
-
usd = preset / rates[day]["AUD"] * (1 + rng.uniform(0, 0.01))
|
|
61
|
-
rows.append(row(usd, day, "Australia"))
|
|
62
|
-
# US cards: euro presets 24/48 at ONE frozen rate for six days, one attempt per card, lunchtime
|
|
63
|
-
frozen = 1.1679
|
|
64
|
-
for _ in range(300):
|
|
65
|
-
day = rng.choice(DAYS[10:16])
|
|
66
|
-
preset = rng.choice([24, 24, 48])
|
|
67
|
-
rows.append(row(round(preset * frozen, 2), day, "United States of America", resp=rng.choice(["A001", "D102"]), avs="Postal code matched", hour=rng.choice([16, 17, 18])))
|
|
68
|
-
# Canada: retail list x 1.06 with US-style billing address
|
|
69
|
-
for _ in range(250):
|
|
70
|
-
day = rng.choice(DAYS)
|
|
71
|
-
price = rng.choice([79.99, 84.99, 89.99, 134.99, 59.95, 239.98, 25.98, 63.98, 137.99, 199.99])
|
|
72
|
-
rows.append(row(round(price * 1.06, 2), day, "Canada", avs="Postal code matched", card="Credit"))
|
|
73
|
-
# Japan: off-menu typed amounts
|
|
74
|
-
for _ in range(200):
|
|
75
|
-
day = rng.choice(DAYS)
|
|
76
|
-
rows.append(row(rng.uniform(15, 400), day, "Japan"))
|
|
77
|
-
return rows
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
class RatesTest(unittest.TestCase):
|
|
81
|
-
def test_lookup_uses_query_date_and_bounded_prior_day_carry(self):
|
|
82
|
-
cache = {"base": "USD", "rates": {
|
|
83
|
-
"2026-08-01": {"EUR": 0.8},
|
|
84
|
-
"2026-08-04": {"EUR": 0.82},
|
|
85
|
-
}}
|
|
86
|
-
cases = [
|
|
87
|
-
("before_cache", "2026-07-31", 7, None, {}),
|
|
88
|
-
("exact_first", "2026-08-01", 7, 0.8, {}),
|
|
89
|
-
("gap", "2026-08-03", 7, 0.8, {"EUR": 1}),
|
|
90
|
-
("exact_last", "2026-08-04", 7, 0.82, {}),
|
|
91
|
-
("after_cache", "2026-08-05", 7, 0.82, {"EUR": 1}),
|
|
92
|
-
("max_carry", "2026-08-11", 7, 0.82, {"EUR": 1}),
|
|
93
|
-
("beyond_carry", "2026-08-12", 7, None, {}),
|
|
94
|
-
("far_after_cache", "2027-08-04", 7, None, {}),
|
|
95
|
-
("configured_limit", "2026-08-06", 1, None, {}),
|
|
96
|
-
("no_carry_missing", "2026-08-05", 0, None, {}),
|
|
97
|
-
("no_carry_exact", "2026-08-04", 0, 0.82, {}),
|
|
98
|
-
]
|
|
99
|
-
for name, day, carry, expected, carried in cases:
|
|
100
|
-
with self.subTest(name=name):
|
|
101
|
-
rates = MODULE.Rates(cache, carry=carry)
|
|
102
|
-
self.assertEqual(rates.rate(day, "EUR"), expected)
|
|
103
|
-
self.assertEqual(dict(rates.carried), carried)
|
|
104
|
-
|
|
105
|
-
def test_missing_currency_searches_prior_quotes_not_just_cache_dates(self):
|
|
106
|
-
rates = MODULE.Rates({"base": "USD", "rates": {
|
|
107
|
-
"2026-08-01": {"EUR": 0.8},
|
|
108
|
-
"2026-08-08": {"GBP": 0.6},
|
|
109
|
-
}}, carry=7)
|
|
110
|
-
self.assertEqual(rates.rate("2026-08-08", "EUR"), 0.8)
|
|
111
|
-
self.assertIsNone(rates.rate("2026-08-09", "EUR"))
|
|
112
|
-
self.assertIsNone(rates.rate("2026-08-08", "CHF"))
|
|
113
|
-
self.assertEqual(dict(rates.carried), {"EUR": 1})
|
|
114
|
-
|
|
115
|
-
def test_identity_and_usd_pegs_do_not_require_dated_quotes(self):
|
|
116
|
-
rates = MODULE.Rates({"base": "USD", "rates": {}}, carry=0)
|
|
117
|
-
self.assertEqual(rates.rate("2026-08-01", "USD"), 1.0)
|
|
118
|
-
self.assertEqual(rates.rate("2026-08-01", "SAR"), 3.75)
|
|
119
|
-
self.assertIsNone(rates.rate("2026-08-01", "EUR"))
|
|
120
|
-
self.assertEqual(dict(rates.carried), {})
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
class RateConsistencyTest(unittest.TestCase):
|
|
124
|
-
def setUp(self):
|
|
125
|
-
self.opt = SimpleNamespace(peak_tol=0.012, frozen_days=4,
|
|
126
|
-
frozen_min_per_day=3, frozen_market_move=0.001)
|
|
127
|
-
|
|
128
|
-
def consistency(self, quotes, charges, wallet="EUR", center=24):
|
|
129
|
-
cache = {"base": "USD", "rates": dict(zip(DAYS, quotes))}
|
|
130
|
-
rows = [
|
|
131
|
-
{"day": day, "currency": currency, "amount": amount}
|
|
132
|
-
for day, daily_charges in zip(DAYS, charges)
|
|
133
|
-
for currency, amount, count in daily_charges
|
|
134
|
-
for _ in range(count)
|
|
135
|
-
]
|
|
136
|
-
return MODULE.rate_consistency(rows, MODULE.Rates(cache), wallet,
|
|
137
|
-
[(center, len(rows))], self.opt)
|
|
138
|
-
|
|
139
|
-
def test_non_usd_source_freezes_when_cross_rate_moves_but_wallet_quote_does_not(self):
|
|
140
|
-
quotes = [{"EUR": 0.8, "GBP": gbp} for gbp in (0.6, 0.6012, 0.6024, 0.6036)]
|
|
141
|
-
result = self.consistency(quotes, [[("GBP", 18, 3)]] * 4)
|
|
142
|
-
self.assertEqual(result["frozen_attempts"], 12)
|
|
143
|
-
self.assertEqual(result["tested_attempts"], 12)
|
|
144
|
-
self.assertEqual(result["frozen_peaks"], 1)
|
|
145
|
-
self.assertTrue(result["detail"][0]["frozen"])
|
|
146
|
-
# EUR per GBP changes from 4/3 to 2000/1509, about 0.5964%.
|
|
147
|
-
self.assertEqual(result["detail"][0]["market_move"], 0.006)
|
|
148
|
-
|
|
149
|
-
def test_matching_source_and_wallet_is_not_frozen_by_usd_quote_movement(self):
|
|
150
|
-
quotes = [{"EUR": eur} for eur in (0.8, 0.804, 0.808, 0.812)]
|
|
151
|
-
result = self.consistency(quotes, [[("EUR", 24, 3)]] * 4)
|
|
152
|
-
self.assertEqual(result["frozen_attempts"], 0)
|
|
153
|
-
self.assertEqual(result["tested_attempts"], 12)
|
|
154
|
-
self.assertEqual(result["live_peaks"], 1)
|
|
155
|
-
self.assertFalse(result["detail"][0]["frozen"])
|
|
156
|
-
self.assertEqual(result["detail"][0]["market_move"], 0.0)
|
|
157
|
-
|
|
158
|
-
def test_parallel_source_and_wallet_quotes_have_no_cross_rate_movement(self):
|
|
159
|
-
quotes = [{"EUR": eur, "GBP": gbp} for eur, gbp in
|
|
160
|
-
((0.8, 0.6), (0.804, 0.603), (0.808, 0.606), (0.812, 0.609))]
|
|
161
|
-
result = self.consistency(quotes, [[("GBP", 18, 3)]] * 4)
|
|
162
|
-
self.assertEqual(result["frozen_attempts"], 0)
|
|
163
|
-
self.assertEqual(result["tested_attempts"], 12)
|
|
164
|
-
self.assertFalse(result["detail"][0]["frozen"])
|
|
165
|
-
self.assertEqual(result["detail"][0]["market_move"], 0.0)
|
|
166
|
-
|
|
167
|
-
def test_live_non_usd_source_tracks_cross_rate(self):
|
|
168
|
-
quotes = [{"EUR": 0.8, "GBP": gbp} for gbp in (0.6, 0.6012, 0.6024, 0.6036)]
|
|
169
|
-
charges = [[("GBP", amount, 3)] for amount in (18, 18.036, 18.072, 18.108)]
|
|
170
|
-
result = self.consistency(quotes, charges)
|
|
171
|
-
self.assertEqual(result["frozen_attempts"], 0)
|
|
172
|
-
self.assertEqual(result["tested_attempts"], 12)
|
|
173
|
-
self.assertFalse(result["detail"][0]["frozen"])
|
|
174
|
-
self.assertEqual(result["detail"][0]["market_move"], 0.006)
|
|
175
|
-
|
|
176
|
-
def test_base_currency_wallet_can_freeze_against_non_base_source(self):
|
|
177
|
-
quotes = [{"EUR": eur} for eur in (0.8, 0.8016, 0.8032, 0.8048)]
|
|
178
|
-
result = self.consistency(quotes, [[("EUR", 24, 3)]] * 4, wallet="USD", center=30)
|
|
179
|
-
self.assertEqual(result["frozen_attempts"], 12)
|
|
180
|
-
self.assertEqual(result["tested_attempts"], 12)
|
|
181
|
-
self.assertTrue(result["detail"][0]["frozen"])
|
|
182
|
-
self.assertEqual(result["detail"][0]["market_move"], 0.006)
|
|
183
|
-
|
|
184
|
-
def test_mixed_sources_keep_modes_movements_and_attempts_separate(self):
|
|
185
|
-
quotes = [{"EUR": 0.8, "GBP": gbp} for gbp in (0.6, 0.6012, 0.6024, 0.6036)]
|
|
186
|
-
result = self.consistency(quotes, [[("EUR", 24, 6), ("GBP", 18, 3)]] * 4)
|
|
187
|
-
self.assertEqual(result["tested_attempts"], 36)
|
|
188
|
-
self.assertEqual(result["frozen_attempts"], 12)
|
|
189
|
-
self.assertEqual(result["frozen_peaks"], 1)
|
|
190
|
-
self.assertEqual(result["live_peaks"], 1)
|
|
191
|
-
self.assertEqual(len(result["detail"]), 2)
|
|
192
|
-
details = {d["source_currency"]: d for d in result["detail"]}
|
|
193
|
-
self.assertFalse(details["EUR"]["frozen"])
|
|
194
|
-
self.assertEqual(details["EUR"]["modal_amounts"], [24])
|
|
195
|
-
self.assertEqual(details["EUR"]["market_move"], 0.0)
|
|
196
|
-
self.assertEqual(details["EUR"]["attempts"], 24)
|
|
197
|
-
self.assertTrue(details["GBP"]["frozen"])
|
|
198
|
-
self.assertEqual(details["GBP"]["modal_amounts"], [18])
|
|
199
|
-
self.assertEqual(details["GBP"]["market_move"], 0.006)
|
|
200
|
-
self.assertEqual(details["GBP"]["attempts"], 12)
|
|
201
|
-
|
|
202
|
-
def test_mixed_sources_cannot_pool_days_or_daily_minimum_for_testing(self):
|
|
203
|
-
quotes = [{"EUR": 0.8, "GBP": 0.6}] * 4
|
|
204
|
-
cases = [
|
|
205
|
-
[[("EUR", 24, 2), ("GBP", 18, 2)]] * 4,
|
|
206
|
-
[[("EUR", 24, 3)]] * 2 + [[("GBP", 18, 3)]] * 2,
|
|
207
|
-
]
|
|
208
|
-
for charges in cases:
|
|
209
|
-
with self.subTest(charges=charges):
|
|
210
|
-
result = self.consistency(quotes, charges)
|
|
211
|
-
self.assertEqual(result["tested_attempts"], 0)
|
|
212
|
-
self.assertEqual(result["frozen_attempts"], 0)
|
|
213
|
-
self.assertEqual(result["detail"], [])
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
class PaymentPatternPresentationTest(unittest.TestCase):
|
|
217
|
-
def run_cli(self, rows, candidates=("EUR",), cache=None, extra=()):
|
|
218
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
219
|
-
root = Path(tmp)
|
|
220
|
-
csv_path = root / "auth.csv"
|
|
221
|
-
with csv_path.open("w", newline="") as fh:
|
|
222
|
-
writer = csv.DictWriter(fh, fieldnames=FIELDS)
|
|
223
|
-
writer.writeheader()
|
|
224
|
-
writer.writerows(rows)
|
|
225
|
-
rates_path = root / "rates.json"
|
|
226
|
-
rates_path.write_text(json.dumps(cache or rates_cache()))
|
|
227
|
-
markdown_path = root / "streams.md"
|
|
228
|
-
cmd = [sys.executable, str(SCRIPT), str(csv_path), "--rates", str(rates_path),
|
|
229
|
-
"--amount-column", "amount", "--currency-column", "currency", "--date-column", "ts",
|
|
230
|
-
"--descriptor-column", "descriptor", "--bin-country-column", "country",
|
|
231
|
-
"--candidate-currencies", *candidates, "--markdown", str(markdown_path), *extra]
|
|
232
|
-
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
233
|
-
self.assertEqual(result.returncode, 0, result.stderr)
|
|
234
|
-
report = json.loads(result.stdout)
|
|
235
|
-
markdown = markdown_path.read_text()
|
|
236
|
-
before = deepcopy(report)
|
|
237
|
-
self.assertEqual(MODULE.to_markdown(report), markdown)
|
|
238
|
-
self.assertEqual(report, before)
|
|
239
|
-
descriptor = report["descriptors"][0]
|
|
240
|
-
self.assertEqual(descriptor["attempts"], len(rows))
|
|
241
|
-
self.assertEqual(sum(s["attempts"] for s in descriptor["streams"]), len(rows))
|
|
242
|
-
for stream in descriptor["streams"] + [s for g in descriptor["groups"] for s in g["substreams"]]:
|
|
243
|
-
p = stream["presentation"]
|
|
244
|
-
self.assertEqual(sum(p["pattern_counts"].values()), stream["attempts"])
|
|
245
|
-
self.assertEqual(sum(p["charge_currencies"].values()), stream["attempts"])
|
|
246
|
-
self.assertEqual(sum(part["attempts"] for part in p["by_charge_currency"]), stream["attempts"])
|
|
247
|
-
return descriptor, markdown
|
|
248
|
-
|
|
249
|
-
def rows(self, charges, country="United Kingdom"):
|
|
250
|
-
return [{"amount": f"{amount:.2f}", "currency": currency, "ts": f"{day} 12:00:00",
|
|
251
|
-
"descriptor": "pattern-fixture", "country": country}
|
|
252
|
-
for day, daily in zip(DAYS, charges)
|
|
253
|
-
for currency, amount, count in daily
|
|
254
|
-
for _ in range(count)]
|
|
255
|
-
|
|
256
|
-
def markdown_row(self, markdown, raw, country=None):
|
|
257
|
-
prefix = f"| {raw} |" if country is None else f"| {country} |"
|
|
258
|
-
matches = [line for line in markdown.splitlines() if line.startswith(prefix) and f"| {raw} |" in line]
|
|
259
|
-
self.assertEqual(len(matches), 1, matches)
|
|
260
|
-
return [cell.strip() for cell in matches[0].split("|")[1:-1]]
|
|
261
|
-
|
|
262
|
-
def test_direct_usd_and_eur_are_based_on_charge_currency_not_legal_tender(self):
|
|
263
|
-
for currency in ("USD", "EUR"):
|
|
264
|
-
with self.subTest(currency=currency):
|
|
265
|
-
rows = self.rows([[(currency, 24, 20)]] * 4)
|
|
266
|
-
descriptor, markdown = self.run_cli(rows, candidates=(currency,))
|
|
267
|
-
group = descriptor["groups"][0]
|
|
268
|
-
stream = group["substreams"][0]
|
|
269
|
-
self.assertEqual(group["legal_tender"], "GBP")
|
|
270
|
-
self.assertEqual(stream["stream"], f"{currency} menu-12 live")
|
|
271
|
-
self.assertEqual(stream["attempts"], 80)
|
|
272
|
-
p = stream["presentation"]
|
|
273
|
-
self.assertEqual(p["pattern_counts"], {"Direct top-up pattern": 80})
|
|
274
|
-
self.assertEqual(p["charge_currencies"], {currency: 80})
|
|
275
|
-
self.assertEqual(p["inferred_top_up_currencies"], [currency])
|
|
276
|
-
self.assertEqual(p["pricing_characteristics"], ["fixed amount"])
|
|
277
|
-
self.assertEqual(p["by_charge_currency"][0]["frozen_fx_attempts"], 0)
|
|
278
|
-
cells = self.markdown_row(markdown, stream["stream"], group["country"])
|
|
279
|
-
self.assertIn(f"Direct top-up pattern: 80 [{currency}: 80]", cells[3])
|
|
280
|
-
self.assertEqual(cells[4:7], [currency, f"{currency}: 80", "fixed amount"])
|
|
281
|
-
self.assertNotIn("frozen FX", cells[3])
|
|
282
|
-
self.assertNotIn("floating", cells[3])
|
|
283
|
-
|
|
284
|
-
def test_fx_currency_and_no_frozen_qualifier_without_positive_cross_rate_test(self):
|
|
285
|
-
rows = self.rows([[('USD', 24 / rates_cache()["rates"][day]["EUR"], 20)] for day in DAYS[:4]])
|
|
286
|
-
descriptor, markdown = self.run_cli(rows)
|
|
287
|
-
stream = descriptor["groups"][0]["substreams"][0]
|
|
288
|
-
self.assertEqual(stream["stream"], "EUR menu-12 live")
|
|
289
|
-
self.assertEqual(stream["presentation"]["pattern_counts"], {"FX-converted top-up pattern": 80})
|
|
290
|
-
self.assertEqual(stream["presentation"]["charge_currencies"], {"USD": 80})
|
|
291
|
-
self.assertEqual(stream["presentation"]["pricing_characteristics"], [])
|
|
292
|
-
cells = self.markdown_row(markdown, stream["stream"])
|
|
293
|
-
self.assertIn("FX-converted top-up pattern: 80 [USD: 80]", cells[1])
|
|
294
|
-
self.assertEqual(cells[2:4], ["EUR", "USD: 80"])
|
|
295
|
-
self.assertEqual(cells[4], "n/a")
|
|
296
|
-
self.assertNotIn("frozen FX", cells[1])
|
|
297
|
-
self.assertNotIn("floating", cells[1])
|
|
298
|
-
|
|
299
|
-
def test_repetition_without_cross_rate_tests_has_no_frozen_qualifier(self):
|
|
300
|
-
charge = 24 / rates_cache()["rates"][DAYS[0]]["EUR"]
|
|
301
|
-
rows = self.rows([[('USD', charge, 80)]])
|
|
302
|
-
descriptor, markdown = self.run_cli(rows)
|
|
303
|
-
stream = descriptor["groups"][0]["substreams"][0]
|
|
304
|
-
self.assertEqual(stream["stream"], "EUR menu-12 live")
|
|
305
|
-
self.assertEqual(stream["rate_consistency"]["tested_attempts"], 0)
|
|
306
|
-
self.assertEqual(stream["rate_consistency"]["detail"], [])
|
|
307
|
-
self.assertEqual(stream["presentation"]["by_charge_currency"][0]["frozen_fx_attempts"], 0)
|
|
308
|
-
cells = self.markdown_row(markdown, stream["stream"])
|
|
309
|
-
self.assertIn("FX-converted top-up pattern: 80 [USD: 80]", cells[1])
|
|
310
|
-
self.assertEqual(cells[4], "n/a")
|
|
311
|
-
self.assertNotIn("frozen", cells[1])
|
|
312
|
-
self.assertNotIn("floating", cells[1])
|
|
313
|
-
|
|
314
|
-
def test_mixed_sources_show_both_types_and_only_tested_source_is_frozen(self):
|
|
315
|
-
cache = {"base": "USD", "rates": {day: {"EUR": 0.8, "GBP": 0.6 + i * 0.0012}
|
|
316
|
-
for i, day in enumerate(DAYS[:4])}}
|
|
317
|
-
rows = self.rows([[('EUR', 24, 12), ('GBP', 18, 8)]] * 4)
|
|
318
|
-
descriptor, markdown = self.run_cli(rows, cache=cache)
|
|
319
|
-
stream = descriptor["groups"][0]["substreams"][0]
|
|
320
|
-
self.assertEqual(stream["stream"], "EUR menu-12 live")
|
|
321
|
-
self.assertEqual(len(descriptor["streams"]), 1)
|
|
322
|
-
self.assertEqual(len(descriptor["groups"][0]["substreams"]), 1)
|
|
323
|
-
p = stream["presentation"]
|
|
324
|
-
self.assertEqual(p["pattern_counts"], {"Direct top-up pattern": 48, "FX-converted top-up pattern": 32})
|
|
325
|
-
self.assertEqual(p["charge_currencies"], {"EUR": 48, "GBP": 32})
|
|
326
|
-
parts = {part["charge_currency"]: part for part in p["by_charge_currency"]}
|
|
327
|
-
self.assertEqual(parts["EUR"]["frozen_fx_attempts"], 0)
|
|
328
|
-
self.assertEqual(parts["GBP"]["frozen_fx_attempts"], 32)
|
|
329
|
-
self.assertEqual(parts["EUR"]["inferred_top_up_currency"], "EUR")
|
|
330
|
-
self.assertEqual(parts["GBP"]["inferred_top_up_currency"], "EUR")
|
|
331
|
-
cells = self.markdown_row(markdown, stream["stream"], "United Kingdom")
|
|
332
|
-
self.assertIn("Direct top-up pattern: 48 [EUR: 48]", cells[3])
|
|
333
|
-
self.assertIn("FX-converted top-up pattern: 32 [GBP: 32 (32 frozen FX tested attempts)]", cells[3])
|
|
334
|
-
self.assertEqual(cells[4:6], ["EUR", "EUR: 48, GBP: 32"])
|
|
335
|
-
self.assertEqual(descriptor["streams"][0]["presentation"], p)
|
|
336
|
-
|
|
337
|
-
def test_summary_aggregates_same_raw_stream_without_splitting_payment_patterns(self):
|
|
338
|
-
direct = self.rows([[('EUR', 24, 20)]] * 4, country="Germany")
|
|
339
|
-
fx = self.rows([[('USD', 24 / rates_cache()["rates"][day]["EUR"], 20)] for day in DAYS[:4]])
|
|
340
|
-
descriptor, markdown = self.run_cli(direct + fx)
|
|
341
|
-
self.assertEqual(len(descriptor["groups"]), 2)
|
|
342
|
-
self.assertEqual(len(descriptor["streams"]), 1)
|
|
343
|
-
stream = descriptor["streams"][0]
|
|
344
|
-
self.assertEqual(stream["stream"], "EUR menu-12 live")
|
|
345
|
-
self.assertEqual(stream["attempts"], 160)
|
|
346
|
-
self.assertEqual(stream["share_of_descriptor"], 1.0)
|
|
347
|
-
self.assertEqual(stream["presentation"]["pattern_counts"], {"Direct top-up pattern": 80, "FX-converted top-up pattern": 80})
|
|
348
|
-
self.assertEqual(stream["presentation"]["charge_currencies"], {"EUR": 80, "USD": 80})
|
|
349
|
-
cells = self.markdown_row(markdown, stream["stream"])
|
|
350
|
-
self.assertIn("Direct top-up pattern: 80 [EUR: 80]", cells[1])
|
|
351
|
-
self.assertIn("FX-converted top-up pattern: 80 [USD: 80]", cells[1])
|
|
352
|
-
|
|
353
|
-
def test_summary_detects_fixed_charges_across_country_dates(self):
|
|
354
|
-
germany = self.rows([[('EUR', 24, 80)]], country="Germany")
|
|
355
|
-
uk = self.rows([[], [('EUR', 24, 80)]], country="United Kingdom")
|
|
356
|
-
descriptor, markdown = self.run_cli(germany + uk, candidates=("EUR",))
|
|
357
|
-
self.assertEqual(len(descriptor["streams"]), 1)
|
|
358
|
-
summary = descriptor["streams"][0]
|
|
359
|
-
self.assertEqual(summary["attempts"], 160)
|
|
360
|
-
self.assertEqual(summary["presentation"]["pattern_counts"], {"Direct top-up pattern": 160})
|
|
361
|
-
self.assertEqual(summary["presentation"]["pricing_characteristics"], ["fixed amount"])
|
|
362
|
-
for group in descriptor["groups"]:
|
|
363
|
-
self.assertEqual(group["substreams"][0]["presentation"]["pricing_characteristics"], [])
|
|
364
|
-
self.assertEqual(self.markdown_row(markdown, summary["stream"])[4], "fixed amount")
|
|
365
|
-
|
|
366
|
-
def test_menu_none_is_other_repeated_amount_not_inferred_top_up(self):
|
|
367
|
-
rows = self.rows([[('EUR', 17.37, 20)]] * 4, country="UNKNOWN")
|
|
368
|
-
descriptor, markdown = self.run_cli(rows)
|
|
369
|
-
stream = descriptor["groups"][0]["substreams"][0]
|
|
370
|
-
self.assertEqual(stream["stream"], "EUR menu-none live")
|
|
371
|
-
self.assertEqual(stream["wallet"], "EUR")
|
|
372
|
-
p = stream["presentation"]
|
|
373
|
-
self.assertEqual(p["pattern_counts"], {"Other pattern": 80})
|
|
374
|
-
self.assertEqual(p["inferred_top_up_currencies"], [])
|
|
375
|
-
self.assertIsNone(p["by_charge_currency"][0]["inferred_top_up_currency"])
|
|
376
|
-
cells = self.markdown_row(markdown, stream["stream"], "UNKNOWN")
|
|
377
|
-
self.assertIn("Other pattern: 80 [EUR: 80]", cells[3])
|
|
378
|
-
self.assertIn("unidentified repeated-amount pattern", cells[3])
|
|
379
|
-
self.assertEqual(cells[4:7], ["n/a", "EUR: 80", "fixed amount"])
|
|
380
|
-
|
|
381
|
-
def test_off_menu_and_small_groups_render_other_with_real_charge_currencies(self):
|
|
382
|
-
for count, extra, raw in ((20, ("--max-substreams", "0"), "off-menu"), (2, (), "small groups")):
|
|
383
|
-
with self.subTest(raw=raw):
|
|
384
|
-
rows = self.rows([[('EUR', 24, count), ('USD', 30, count)]] * 4)
|
|
385
|
-
descriptor, markdown = self.run_cli(rows, extra=extra)
|
|
386
|
-
stream = descriptor["streams"][0]
|
|
387
|
-
self.assertEqual(stream["stream"], raw)
|
|
388
|
-
self.assertEqual(stream["presentation"]["pattern_counts"], {"Other pattern": len(rows)})
|
|
389
|
-
self.assertEqual(stream["presentation"]["inferred_top_up_currencies"], [])
|
|
390
|
-
self.assertEqual(stream["presentation"]["charge_currencies"], {"EUR": count * 4, "USD": count * 4})
|
|
391
|
-
cells = self.markdown_row(markdown, raw)
|
|
392
|
-
self.assertIn(f"Other pattern: {len(rows)}", cells[1])
|
|
393
|
-
self.assertEqual(cells[2], "n/a")
|
|
394
|
-
self.assertEqual(cells[3], f"EUR: {count * 4}, USD: {count * 4}")
|
|
395
|
-
self.assertNotIn("top-up pattern", cells[1])
|
|
396
|
-
|
|
397
|
-
def test_retail_renders_ecommerce_without_tax_fee_or_wallet_claim(self):
|
|
398
|
-
rows = [r for r in synthetic_rows() if r["country"] == "Canada"]
|
|
399
|
-
descriptor, markdown = self.run_cli(rows)
|
|
400
|
-
stream = descriptor["groups"][0]["substreams"][0]
|
|
401
|
-
self.assertTrue(stream["stream"].startswith("retail x"))
|
|
402
|
-
self.assertAlmostEqual(stream["retail"]["constant"], 1.06, places=3)
|
|
403
|
-
p = stream["presentation"]
|
|
404
|
-
self.assertEqual(p["pattern_counts"], {"E-commerce pattern": stream["attempts"]})
|
|
405
|
-
self.assertEqual(p["inferred_top_up_currencies"], [])
|
|
406
|
-
self.assertEqual(p["charge_currencies"], {"USD": stream["attempts"]})
|
|
407
|
-
cells = self.markdown_row(markdown, stream["stream"], "Canada")
|
|
408
|
-
self.assertIn(f"E-commerce pattern: {stream['attempts']} [USD: {stream['attempts']}]", cells[3])
|
|
409
|
-
self.assertEqual(cells[4], "n/a")
|
|
410
|
-
self.assertNotIn("tax", markdown.lower())
|
|
411
|
-
self.assertNotIn("fee", markdown.lower())
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
class DetectStreamsTest(unittest.TestCase):
|
|
415
|
-
@classmethod
|
|
416
|
-
def setUpClass(cls):
|
|
417
|
-
cls.tmp = tempfile.TemporaryDirectory()
|
|
418
|
-
root = Path(cls.tmp.name)
|
|
419
|
-
cls.csv = root / "auth.csv"
|
|
420
|
-
with cls.csv.open("w", newline="") as fh:
|
|
421
|
-
w = csv.DictWriter(fh, fieldnames=FIELDS)
|
|
422
|
-
w.writeheader()
|
|
423
|
-
w.writerows(synthetic_rows())
|
|
424
|
-
cls.rates = root / "rates.json"
|
|
425
|
-
cls.rates.write_text(json.dumps(rates_cache()))
|
|
426
|
-
cls.out = root / "streams.json"
|
|
427
|
-
cmd = [sys.executable, str(SCRIPT), str(cls.csv), "--rates", str(cls.rates), "--amount-column", "amount", "--currency-column", "currency",
|
|
428
|
-
"--date-column", "ts", "--descriptor-column", "descriptor", "--bin-country-column", "country", "--response-column", "response",
|
|
429
|
-
"--account-column", "account", "--card-type-column", "card_type", "--avs-column", "avs", "--auth-column", "auth",
|
|
430
|
-
"--output", str(cls.out), "--markdown", str(root / "streams.md")]
|
|
431
|
-
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
432
|
-
assert result.returncode == 0, result.stderr
|
|
433
|
-
cls.report = json.loads(cls.out.read_text())
|
|
434
|
-
cls.groups = {g["country"]: g for g in cls.report["descriptors"][0]["groups"]}
|
|
435
|
-
|
|
436
|
-
@classmethod
|
|
437
|
-
def main_sub(cls, country):
|
|
438
|
-
return max(cls.groups[country]["substreams"], key=lambda s: s["attempts"])
|
|
439
|
-
|
|
440
|
-
@classmethod
|
|
441
|
-
def tearDownClass(cls):
|
|
442
|
-
cls.tmp.cleanup()
|
|
443
|
-
|
|
444
|
-
def test_euro_wallet_inferred_for_germany_with_10_scheme_live(self):
|
|
445
|
-
g = self.main_sub("Germany")
|
|
446
|
-
self.assertEqual(g["wallet"], "EUR")
|
|
447
|
-
self.assertEqual(g["scheme"], "10")
|
|
448
|
-
self.assertFalse(g["frozen"])
|
|
449
|
-
peaks = [c for c, _ in g["peaks"][:3]]
|
|
450
|
-
self.assertTrue(all(any(abs(c - m) <= 0.012 * m for m in (10, 20, 50)) for c in peaks), peaks)
|
|
451
|
-
|
|
452
|
-
def test_aud_wallet_inferred_for_australia(self):
|
|
453
|
-
g = self.main_sub("Australia")
|
|
454
|
-
self.assertEqual(g["wallet"], "AUD")
|
|
455
|
-
self.assertTrue(any(abs(c - 30) <= 0.4 for c, _ in g["peaks"]))
|
|
456
|
-
|
|
457
|
-
def test_us_cards_on_euro_menu_are_flagged_frozen(self):
|
|
458
|
-
g = self.main_sub("United States of America")
|
|
459
|
-
self.assertEqual(g["wallet"], "EUR")
|
|
460
|
-
self.assertEqual(g["scheme"], "12")
|
|
461
|
-
self.assertTrue(g["frozen"], g["rate_consistency"])
|
|
462
|
-
self.assertIn("frozen", g["stream"])
|
|
463
|
-
self.assertLess(g["behaviour"]["repeat_card_share"], 0.05)
|
|
464
|
-
|
|
465
|
-
def test_retail_constant_detected_for_canada(self):
|
|
466
|
-
g = self.main_sub("Canada")
|
|
467
|
-
self.assertTrue(g["stream"].startswith("retail"), g["stream"])
|
|
468
|
-
self.assertAlmostEqual(g["retail"]["constant"], 1.06, places=3)
|
|
469
|
-
|
|
470
|
-
def test_japan_is_off_menu(self):
|
|
471
|
-
self.assertEqual(self.main_sub("Japan")["stream"], "off-menu")
|
|
472
|
-
|
|
473
|
-
def test_streams_summarised_per_descriptor(self):
|
|
474
|
-
labels = {s["stream"] for s in self.report["descriptors"][0]["streams"]}
|
|
475
|
-
self.assertTrue(any(l.startswith("EUR menu-10 live") for l in labels), labels)
|
|
476
|
-
self.assertTrue(any(l.startswith("EUR menu-12 frozen") for l in labels), labels)
|
|
477
|
-
self.assertTrue(any(l.startswith("retail") for l in labels), labels)
|
|
478
|
-
|
|
479
|
-
def test_same_currency_charges_produce_live_stream_through_cli(self):
|
|
480
|
-
rows = [
|
|
481
|
-
{"amount": "24.00", "currency": "EUR", "ts": f"{day} 12:00:00",
|
|
482
|
-
"descriptor": "EUR-only", "country": "Germany"}
|
|
483
|
-
for day in DAYS[:4]
|
|
484
|
-
for _ in range(20)
|
|
485
|
-
]
|
|
486
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
487
|
-
root = Path(tmp)
|
|
488
|
-
csv_path = root / "auth.csv"
|
|
489
|
-
with csv_path.open("w", newline="") as fh:
|
|
490
|
-
writer = csv.DictWriter(fh, fieldnames=FIELDS)
|
|
491
|
-
writer.writeheader()
|
|
492
|
-
writer.writerows(rows)
|
|
493
|
-
rates_path = root / "rates.json"
|
|
494
|
-
rates_path.write_text(json.dumps(rates_cache()))
|
|
495
|
-
cmd = [sys.executable, str(SCRIPT), str(csv_path), "--rates", str(rates_path),
|
|
496
|
-
"--amount-column", "amount", "--currency-column", "currency", "--date-column", "ts",
|
|
497
|
-
"--descriptor-column", "descriptor", "--bin-country-column", "country",
|
|
498
|
-
"--candidate-currencies", "EUR"]
|
|
499
|
-
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
500
|
-
self.assertEqual(result.returncode, 0, result.stderr)
|
|
501
|
-
report = json.loads(result.stdout)
|
|
502
|
-
descriptor = report["descriptors"][0]
|
|
503
|
-
self.assertEqual(descriptor["streams"][0]["stream"], "EUR menu-12 live")
|
|
504
|
-
stream = descriptor["groups"][0]["substreams"][0]
|
|
505
|
-
self.assertEqual(stream["attempts"], len(rows))
|
|
506
|
-
self.assertFalse(stream["frozen"])
|
|
507
|
-
self.assertEqual(stream["rate_consistency"]["tested_attempts"], len(rows))
|
|
508
|
-
self.assertEqual(stream["rate_consistency"]["frozen_attempts"], 0)
|
|
509
|
-
self.assertEqual(stream["rate_consistency"]["detail"][0]["market_move"], 0.0)
|
|
510
|
-
|
|
511
|
-
def test_peaks_disappear_under_jitter_control(self):
|
|
512
|
-
vals = [10.0] * 50 + [20.0] * 30
|
|
513
|
-
cov, _ = MODULE.coverage(vals, 0.012, 0.02, 10)
|
|
514
|
-
self.assertGreater(cov, 0.99)
|
|
515
|
-
ctrl = MODULE.coverage_against(MODULE.jitter(vals, random.Random(1), 0.02, 0.05), [10.0, 20.0], 0.012)
|
|
516
|
-
self.assertLess(ctrl, 0.05)
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if __name__ == "__main__":
|
|
520
|
-
unittest.main()
|