Personal Telegram developer console for GitHub

test: harden repository id fallback boundaries

davoodmehraban89 committed Oct 4, 2026 at 06:36 UTC 23d1d10c7d134415ad334fc63bd4b09aaccb3ec8
1 file changed +61
test/github-repository-fallback.test.js
+61
@@ -68,3 +68,64 @@ test('numeric private repository lookup falls back through accessible repositori
68 globalThis.fetch = originalFetch;
69 }
70 });
71 +
72 +test('numeric repository lookup does not fall back for non-404 provider failures', async () => {
73 + const originalFetch = globalThis.fetch;
74 + const calls = [];
75 + const repoId = 1401612143;
76 +
77 + globalThis.fetch = async url => {
78 + const value = String(url);
79 + calls.push(value);
80 + if (value === `https://api.github.com/repositories/${repoId}`) {
81 + return json({ message: 'Resource not accessible by personal access token' }, 403);
82 + }
83 + throw new Error(`Unexpected fallback URL: ${value}`);
84 + };
85 +
86 + try {
87 + const github = new GitHubService('test-token', 'davoodmehraban89');
88 + await assert.rejects(
89 + () => github.getRepository(repoId),
90 + /GitHub repository failed: 403 Resource not accessible by personal access token/
91 + );
92 + assert.deepEqual(calls, [`https://api.github.com/repositories/${repoId}`]);
93 + } finally {
94 + globalThis.fetch = originalFetch;
95 + }
96 +});
97 +
98 +test('numeric repository 404 preserves the original failure when no accessible repository matches the id', async () => {
99 + const originalFetch = globalThis.fetch;
100 + const calls = [];
101 + const repoId = 1401612143;
102 +
103 + globalThis.fetch = async url => {
104 + const value = String(url);
105 + calls.push(value);
106 + if (value === `https://api.github.com/repositories/${repoId}`) {
107 + return json({ message: 'Not Found' }, 404);
108 + }
109 + if (value.startsWith('https://api.github.com/user/repos?')) {
110 + return json([{
111 + id: 42,
112 + name: 'another-repo',
113 + full_name: 'davoodmehraban89/another-repo',
114 + private: true,
115 + default_branch: 'main'
116 + }]);
117 + }
118 + throw new Error(`Unexpected URL: ${value}`);
119 + };
120 +
121 + try {
122 + const github = new GitHubService('test-token', 'davoodmehraban89');
123 + await assert.rejects(
124 + () => github.getRepository(repoId),
125 + /GitHub repository failed: 404 Not Found/
126 + );
127 + assert.equal(calls.length, 2);
128 + } finally {
129 + globalThis.fetch = originalFetch;
130 + }
131 +});