Files
Libation/Source/_Tests/LibationCli.Tests/PdfBackFillOptionsTests.cs
T
Cursor Agentandrmcrackan 870b596d3e fix(cli): download the PDFs of titles whose audio is already downloaded
A plain 'libationcli liberate' iterates the titles DownloadDecryptBook selects,
and that step selects on '!AudioExists'. A title needing nothing but its PDF was
therefore never reached by the verb documented as 'book and pdf backups' - only
'liberate --pdf' picked it up. For a library that was liberated before its PDFs
were, that is every title with a PDF.

Give the bulk run an optional second pass and have liberate use it for PDFs, the
way the app's Liberate All always has. Skipped when the first pass stopped early
so a run cut short by its download limit does not carry on doing other work, and
titles the first pass attempted are excluded by product id rather than by asking
Validate again, so a step that just failed is not immediately retried.

Left alone: the Audiobookshelf upload stays tied to a fresh liberation. Its
Validate passes for any liberated title, so including it here would walk the
whole library on the next run. 'abs upload' already exists for that.

Co-authored-by: rmcrackan <rmcrackan@gmail.com>
2026-08-16 17:01:29 +00:00

51 lines
1.5 KiB
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
namespace LibationCli.Tests;
/// <summary>
/// Which liberate runs also pick up titles that need nothing but their PDF. Reported in issue #1947: the CLI
/// had never downloaded PDFs for titles it had already downloaded the audio of.
/// </summary>
[TestClass]
public class PdfBackFillOptionsTests
{
private static LiberateOptions Parse(params string[] args)
{
using var error = new StringWriter();
var options = Program.ParseInvocation(args, error).Result?.Value as LiberateOptions;
Assert.IsNotNull(options);
return options;
}
[TestMethod]
public void A_plain_run_picks_them_up()
=> Assert.IsTrue(Parse("liberate").BackFillsPdfs);
[TestMethod]
public void A_forced_run_picks_them_up()
=> Assert.IsTrue(Parse("liberate", "--force").BackFillsPdfs);
[TestMethod]
public void A_run_with_a_download_limit_picks_them_up()
=> Assert.IsTrue(Parse("liberate", "--limit-books", "5").BackFillsPdfs);
[TestMethod]
[DataRow("--pdf")]
[DataRow("-p")]
public void A_pdf_only_run_needs_no_second_pass(string pdfOnly)
{
// It selects those titles to begin with.
Assert.IsFalse(Parse("liberate", pdfOnly).BackFillsPdfs);
}
[TestMethod]
[DataRow("liberate", "B017V4IM1G")]
[DataRow("liberate", "--id", "B017V4IM1G")]
public void A_run_that_names_its_titles_needs_no_second_pass(params string[] args)
{
// Naming a title re-downloads it, so its PDF follows from the main pass.
Assert.IsFalse(Parse(args).BackFillsPdfs);
}
}