event 1320 solution

This commit is contained in:
elffuss-bot
2026-10-11 13:53:58 +00:00
parent aea0a26bf6
commit bb9726da7d
2 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
diff --git a/tests/acceptance/8/CRITERIA.json b/tests/acceptance/8/CRITERIA.json
new file mode 100644
index 0000000000000000000000000000000000000000..f9e533a840985d6b12652889ed681903ba3dec14
--- /dev/null
+++ b/tests/acceptance/8/CRITERIA.json
@@ -0,0 +1,18 @@
+{
+ "schema": "elffuss-t2t/criteria@2",
+ "issue": 8,
+ "criteria": [
+ {
+ "index": 1,
+ "tests": [
+ "tests/acceptance/8/criteria.test.js::criterion 1"
+ ]
+ },
+ {
+ "index": 2,
+ "tests": [
+ "tests/acceptance/8/criteria.test.js::criterion 2"
+ ]
+ }
+ ]
+}
diff --git a/tests/acceptance/8/criteria.test.js b/tests/acceptance/8/criteria.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..3dae187554d132eaf25ebe94aeb7c87dd5e5a9ca
--- /dev/null
+++ b/tests/acceptance/8/criteria.test.js
@@ -0,0 +1,27 @@
+import { test } from 'node:test'
+import assert from 'node:assert/strict'
+import { readFileSync } from 'node:fs'
+import * as mod from '../../../web/js/tools/clone.js' // the code under test: call it as mod.<name>(...)
+const source = readFileSync(new URL('../../../web/js/tools/clone.js', import.meta.url), 'utf8') // the text of web/js/tools/clone.js, for a criterion about how the file is written
+
+test('criterion 1', () => {
+ // `parseRepoUrl("https://github.com/o/r.git/")` returns `{ host: "github", owner: "o", repo: "r", branch: null }`, and `parseRepoUrl("https://github.com/o/r/tree/dev")` still returns branch `"dev"`.
+ const result1 = mod.parseRepoUrl("https://github.com/o/r.git/")
+ assert.deepStrictEqual(result1, { host: "github", owner: "o", repo: "r", branch: null })
+
+ const result2 = mod.parseRepoUrl("https://github.com/o/r/tree/dev")
+ assert.equal(result2.branch, "dev")
+})
+
+test('criterion 2', () => {
+ // `parseRepoUrl("https://bitbucket.org/o/r.git/")` returns `{ host: "bitbucket", owner: "o", repo: "r", branch: null }`, and `parseRepoUrl("https://example.org/o/r")` still throws an Error.
+ const result1 = mod.parseRepoUrl("https://bitbucket.org/o/r.git/")
+ assert.deepStrictEqual(result1, { host: "bitbucket", owner: "o", repo: "r", branch: null })
+
+ try {
+ mod.parseRepoUrl("https://example.org/o/r")
+ assert.fail("Expected parseRepoUrl to throw an Error for invalid URL")
+ } catch (e) {
+ // Expected error
+ }
+})
diff --git a/web/js/tools/clone.js b/web/js/tools/clone.js
index 09ee334f934df2af3420147792b703d3e9f40209..78bf781095587319132a5c4832a2b56b72e234f4 100644
--- a/web/js/tools/clone.js
+++ b/web/js/tools/clone.js
@@ -12,7 +12,7 @@ const MAX_FILE_BYTES = 4 * 1024 * 1024; // ficheros más grandes se saltan (bina
const CONCURRENCY = 10;
export function parseRepoUrl(raw) {
- const url = String(raw || '').trim().replace(/\.git$/, '').replace(/\/+$/, '');
+ const url = String(raw || '').trim().replace(/\/+$/, '').replace(/\.git$/, '');
let m = url.match(/^(?:https?:\/\/)?(?:www\.)?github\.com\/([\w.-]+)\/([\w.-]+)(?:\/tree\/([\w./-]+))?/i);
if (m) return { host: 'github', owner: m[1], repo: m[2], branch: m[3] || null };
m = url.match(/^(?:https?:\/\/)?(?:www\.)?bitbucket\.org\/([\w.-]+)\/([\w.-]+)(?:\/src\/([\w./-]+))?/i);

1
events/0000001320.json Normal file
View File

@@ -0,0 +1 @@
{"data":{"cites":[],"envelope":{"delegation":{"identity":"0x6b51d8b8ae3ff4e4f6e7b585b78ef1cda12586b5","nonce":"1791726787","project":"0x0000000000000000000000000000000000000000000000000000000000000000","scopes":3,"sessionX":"0x10d8e4f6f95d65dcec54386e5d0bc7642d52911985d5784d02c92b049b313067","sessionY":"0xe693916725e1b73904764a9120a02ce9b46711eeab104b9f18052b23dbe756ee","validFrom":"1791726787","validUntil":"1792331587"},"delegationSignature":"0x5affe654d471f3e6d2fb2072966232210c949876665e18f617ca7a46a58e26eb1d9eb7b3f9f5dd6ee31c710820c75b32d48e6ba676a004bbd287d1d7c164dedb1c","kind":"session","signature":"0x35f91483aa81293e637565036d6a7f81fb8ce9333740af11dd4d5c9a525009175a4b91b862e03ecc81db1941cee1a4d99d2bc0c92d4d67049814e19fa6620757"},"mainHead":null,"message":{"author":"0x6b51d8b8ae3ff4e4f6e7b585b78ef1cda12586b5","baseCommit":"0xf0bf4465c7b2c9c58ca12b934548b20d27b13cbd","basePartial":"0x0000000000000000000000000000000000000000000000000000000000000000","citesHash":"0x0000000000000000000000000000000000000000000000000000000000000000","issueId":"0xb39df7f42e2f2a5fe2272fbd62986ee6a0738e02391e5725f8b27a3a20f68b29","issuedAt":"1791726837","lines":2,"nonce":"1791726837000","patchHash":"0x35a333fb67ac586463c5ed6ab9ee695d3ca8b946e30e035a7fa83eceea3b5fdb","project":"0x16d6e75341c5f21003a4d9e89b416a545f7335094d7df139fd20942c9b7fb2de","repo":"0xd822e541c0173492ca0725a08935bcd8eaa756a9559600a9427d0daac625ead2"},"pr":"elffuss/code:item/0x4b216fde14d58ea61dbd8ef6f505e9a73b37e8ae6461eef00b0e51d7b62b097c"},"eventHash":"0xdc02402141f3e03faf57b0088859df8a5ff469a763c73ab10c4a41bd335a75ce","gatewaySignature":"0xc7b2a12826ad734cc6c36c127ced951457f8646c89be2e49117901cdee81dce932cb2ef502a0f0b5894330b4717a9097191b1cad62c2cfb2478abaf91e1a414c1b","prev":"0x4ef7b6391ff5879c449e872463c71d2e8299c3d40d72ce407b7ca15c5668a5a4","seq":1320,"ts":1791726838,"type":"solution","v":2}