|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import { unitTest } from "../../test.ts"; |
8 | | -import { assert, assertEquals } from "testing/asserts"; |
9 | | -import { tinyTexPkgName } from "../../../src/tools/impl/tinytex.ts"; |
| 8 | +import { assert, assertEquals, assertRejects } from "testing/asserts"; |
| 9 | +import { |
| 10 | + tinyTexInstallable, |
| 11 | + tinyTexPkgName, |
| 12 | +} from "../../../src/tools/impl/tinytex.ts"; |
10 | 13 | import { getLatestRelease } from "../../../src/tools/github.ts"; |
11 | | -import { GitHubRelease } from "../../../src/tools/types.ts"; |
| 14 | +import { GitHubRelease, InstallContext, PackageInfo } from "../../../src/tools/types.ts"; |
| 15 | +import { join } from "../../../src/deno_ral/path.ts"; |
| 16 | +import { isLinux } from "../../../src/deno_ral/platform.ts"; |
12 | 17 |
|
13 | 18 | // ---- Pure logic tests for tinyTexPkgName ---- |
14 | 19 |
|
@@ -158,3 +163,92 @@ unitTest( |
158 | 163 | assertAssetExists(candidates, assetNames, "Windows"); |
159 | 164 | }, |
160 | 165 | ); |
| 166 | + |
| 167 | +// ---- Extraction failure tests ---- |
| 168 | + |
| 169 | +function createMockContext(workingDir: string): InstallContext { |
| 170 | + return { |
| 171 | + workingDir, |
| 172 | + info: (_msg: string) => {}, |
| 173 | + withSpinner: async (_options, op) => { |
| 174 | + await op(); |
| 175 | + }, |
| 176 | + error: (_msg: string) => {}, |
| 177 | + confirm: async (_msg: string) => true, |
| 178 | + download: async (_name: string, _url: string, _target: string) => {}, |
| 179 | + props: {}, |
| 180 | + flags: {}, |
| 181 | + }; |
| 182 | +} |
| 183 | + |
| 184 | +unitTest( |
| 185 | + "install - throws on extraction failure for corrupt archive", |
| 186 | + async () => { |
| 187 | + const workingDir = Deno.makeTempDirSync({ prefix: "quarto-tinytex-test" }); |
| 188 | + try { |
| 189 | + // Create a corrupt .tar.xz file that tar cannot extract |
| 190 | + const badArchive = join( |
| 191 | + workingDir, |
| 192 | + "TinyTeX-linux-x86_64-v2026.04.tar.xz", |
| 193 | + ); |
| 194 | + Deno.writeTextFileSync(badArchive, "this is not a valid archive"); |
| 195 | + |
| 196 | + const pkgInfo: PackageInfo = { |
| 197 | + filePath: badArchive, |
| 198 | + version: "v2026.04", |
| 199 | + }; |
| 200 | + const context = createMockContext(workingDir); |
| 201 | + |
| 202 | + await assertRejects( |
| 203 | + () => tinyTexInstallable.install(pkgInfo, context), |
| 204 | + Error, |
| 205 | + "Failed to extract", |
| 206 | + ); |
| 207 | + } finally { |
| 208 | + Deno.removeSync(workingDir, { recursive: true }); |
| 209 | + } |
| 210 | + }, |
| 211 | +); |
| 212 | + |
| 213 | +unitTest( |
| 214 | + "install - extraction failure for .tar.xz includes xz-utils hint only on Linux", |
| 215 | + async () => { |
| 216 | + const workingDir = Deno.makeTempDirSync({ prefix: "quarto-tinytex-test" }); |
| 217 | + try { |
| 218 | + const badArchive = join( |
| 219 | + workingDir, |
| 220 | + "TinyTeX-linux-x86_64-v2026.04.tar.xz", |
| 221 | + ); |
| 222 | + Deno.writeTextFileSync(badArchive, "this is not a valid archive"); |
| 223 | + |
| 224 | + const pkgInfo: PackageInfo = { |
| 225 | + filePath: badArchive, |
| 226 | + version: "v2026.04", |
| 227 | + }; |
| 228 | + const context = createMockContext(workingDir); |
| 229 | + |
| 230 | + try { |
| 231 | + await tinyTexInstallable.install(pkgInfo, context); |
| 232 | + throw new Error("Expected install to throw"); |
| 233 | + } catch (e) { |
| 234 | + assert( |
| 235 | + e instanceof Error && e.message.includes("Failed to extract"), |
| 236 | + `Error should indicate extraction failure, got: ${e}`, |
| 237 | + ); |
| 238 | + if (isLinux) { |
| 239 | + assert( |
| 240 | + e.message.includes("xz-utils"), |
| 241 | + `On Linux, error should mention xz-utils, got: ${e.message}`, |
| 242 | + ); |
| 243 | + } else { |
| 244 | + assert( |
| 245 | + !e.message.includes("xz-utils"), |
| 246 | + `On non-Linux, error should not mention xz-utils, got: ${e.message}`, |
| 247 | + ); |
| 248 | + } |
| 249 | + } |
| 250 | + } finally { |
| 251 | + Deno.removeSync(workingDir, { recursive: true }); |
| 252 | + } |
| 253 | + }, |
| 254 | +); |
0 commit comments