Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package packit.model.dto
data class RunnerPackageDto(
val name: String,
val version: String,
val location: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ class RunnerControllerTest : IntegrationTest() {
HttpMethod.GET,
getTokenizedHttpEntity()
)
assertEquals(listOf(RunnerPackageDto(name = "minimalRPackage", version = "0.0.1")), res.body)
assertThat(
res.body
).contains(RunnerPackageDto(name = "minimalRPackage", version = "0.0.1", location = "/library"))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package packit.integration.services

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Value
Expand Down Expand Up @@ -51,7 +52,9 @@ class OrderlyRunnerClientTest(
val result = sut.getPackages()

assertIs<List<RunnerPackageDto>>(result)
assertEquals(listOf(RunnerPackageDto(name = "minimalRPackage", version = "0.0.1")), result)
assertThat(
result
).contains(RunnerPackageDto(name = "minimalRPackage", version = "0.0.1", location = "/library"))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import kotlin.test.assertEquals
class RunnerControllerTest {
private val runnerService = mock<RunnerService> {
on { getPackages() } doReturn listOf(
RunnerPackageDto("package1", "1.0.0"),
RunnerPackageDto("package2", "2.0.0"),
RunnerPackageDto("package1", "1.0.0", "/library"),
RunnerPackageDto("package2", "2.0.0", "/usr/lib/R/library"),
)
}

Expand All @@ -33,5 +33,8 @@ class RunnerControllerTest {
assertThat(
listOf(responseBody?.get(0)?.version, responseBody?.get(1)?.version)
).containsExactly("1.0.0", "2.0.0")
assertThat(
listOf(responseBody?.get(0)?.location, responseBody?.get(1)?.location)
).containsExactly("/library", "/usr/lib/R/library")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class RunnerServiceTest {
private val client = mock<OrderlyRunner> {
on { getVersion() } doReturn version
on { getPackages() } doReturn listOf(
RunnerPackageDto("package1", "1.0.0"),
RunnerPackageDto("package2", "2.0.0"),
RunnerPackageDto("package1", "1.0.0", "/library"),
RunnerPackageDto("package2", "2.0.0", "/usr/lib/R/library"),
)
}
private val runInfoRepository = mock<RunInfoRepository> {
Expand Down Expand Up @@ -91,8 +91,8 @@ class RunnerServiceTest {
val result = sut.getPackages()
assertEquals(
listOf(
RunnerPackageDto("package1", "1.0.0"),
RunnerPackageDto("package2", "2.0.0"),
RunnerPackageDto("package1", "1.0.0", "/library"),
RunnerPackageDto("package2", "2.0.0", "/usr/lib/R/library"),
),
result
)
Expand Down
12 changes: 3 additions & 9 deletions app/e2e/runnerPage.demo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import { Locator } from "@playwright/test";
import { test, expect, TAG_DEMO_R_LIBRARY } from "./tagCheckFixture";
import { getContentLocator } from "./utils";

test.describe("Runner page", () => {
let content: Locator;

test.beforeEach(async ({ page }) => {
await page.goto("./");
content = await getContentLocator(page);
await page.getByRole("link", { name: "Runner" }).click();
});

test.describe("Packages tab", { tag: TAG_DEMO_R_LIBRARY }, () => {
// Expect the example R package to be listed as installed; this package will not be present on
// demo or prod environments, nor if PACKIT_HOST_R_LIBRARY_PATH was set to anything other than
// the `./scripts/runnerDemoLib` path when running dependencies.
// See api/README.md for more details.
test("can see list of installed packages", async ({ page }) => {
await page.goto("./");
const content = await getContentLocator(page);
await page.getByRole("link", { name: "Runner" }).click();
await page.getByRole("link", { name: "Package versions" }).click();
await expect(content.getByText(/minimalRPackage.*0\.0\.1/)).toBeVisible();
});
Expand Down
63 changes: 46 additions & 17 deletions app/src/app/components/contents/runner/PacketRunnerPackages.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Library } from "lucide-react";
import { useGetPackages } from "./hooks/useGetPackages";
import { Skeleton } from "@components/Base/Skeleton";
import { HttpStatus } from "@lib/types/HttpStatus";
import { Unauthorized } from "../common/Unauthorized";
import { ErrorComponent } from "../common/ErrorComponent";
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@components/Base/Accordion";

export const PacketRunnerPackages = () => {
const { packages, error } = useGetPackages();
Expand All @@ -19,29 +19,58 @@ export const PacketRunnerPackages = () => {
return <Skeleton className="w-full h-32" />;
}

const sharedLibraryPackages = packages.filter((pkg) => pkg.location === "/library");
const otherPackages = packages.filter((pkg) => pkg.location !== "/library");

return (
<>
<div>
<h2 className="text-2xl font-bold tracking-tight">Package versions</h2>
<p className="text-muted-foreground">View installed R packages and versions</p>
</div>
<div className="space-y-4 mt-4">
<p>
This list includes only the additional packages installed in the runner&rsquo;s R library for use by reports,
and excludes some standard packages.
</p>
<span className="flex gap-1 items-center">
<Library className="small-icon text-muted-foreground" />
<h3 className="text-lg">Installed packages</h3>
</span>
<ul className="space-y-1">
{packages.map((pkg, name) => (
<li key={name}>
<span className="font-semibold mr-2">{pkg.name}</span>
<span className="text-muted-foreground">{pkg.version}</span>
</li>
))}
</ul>
<Accordion type="single" collapsible defaultValue="library" className="w-full">
<AccordionItem value="library">
<AccordionTrigger>
<h3>Runner packages</h3>
</AccordionTrigger>
<AccordionContent>
<p>
This list includes only the additional packages installed in the runner&rsquo;s R library for use by
reports.
</p>
<ul className="space-y-1 mt-4 overflow-y-auto" style={{ maxHeight: "1000px" }}>
{sharedLibraryPackages.map((pkg, name) => (
<li key={name}>
<span className="font-semibold mr-2">{pkg.name}</span>
<span className="text-muted-foreground">{pkg.version}</span>
</li>
))}
</ul>
</AccordionContent>
</AccordionItem>
<AccordionItem value="other">
<AccordionTrigger>
<h3>Other packages</h3>
</AccordionTrigger>
<AccordionContent>
<p>
This list includes packages that are part of the base R installation, or which are available in the
runner environment without having been specifically installed in the runner&rsquo;s R library. They are
included here for reference. It is recommended to specifically install any packages your reports depend
on in the runner&rsquo;s R library to ensure consistent behavior across different environments.
</p>
<ul className="space-y-1 mt-4 overflow-y-auto" style={{ maxHeight: "1000px" }}>
{otherPackages.map((pkg, name) => (
<li key={name}>
<span className="font-semibold mr-2">{pkg.name}</span>
<span className="text-muted-foreground">{pkg.version}</span>
</li>
))}
</ul>
</AccordionContent>
</AccordionItem>
</Accordion>
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { PacketRunnerPackages } from "@components/contents/runner";
import { mockRunnerPackages } from "@/tests/mocks";
import { SWRConfig } from "swr";
Expand All @@ -18,17 +19,35 @@ describe("PacketRunnerPackages component", () => {
</SWRConfig>
);

it("should render packages page with a list of installed packages", async () => {
it("should render packages page with accordion sections for library and other packages", async () => {
renderComponent();

await waitFor(() => {
expect(screen.getByText("Package versions")).toBeVisible();
});

mockRunnerPackages.forEach((pkg) => {
expect(screen.getByText("Runner packages")).toBeVisible();
expect(screen.getByText("Other packages")).toBeVisible();

const libraryPackages = mockRunnerPackages.filter((pkg) => pkg.location === "/library");
const otherPackages = mockRunnerPackages.filter((pkg) => pkg.location !== "/library");
libraryPackages.forEach((pkg) => {
expect(screen.getByText(pkg.name)).toBeVisible();
expect(screen.getByText(pkg.version)).toBeVisible();
});
otherPackages.forEach((pkg) => {
expect(screen.queryByText(pkg.name)).not.toBeInTheDocument();
expect(screen.queryByText(pkg.version)).not.toBeInTheDocument();
});

await userEvent.click(screen.getByText("Other packages"));

await waitFor(() => {
otherPackages.forEach((pkg) => {
expect(screen.getByText(pkg.name)).toBeVisible();
expect(screen.getByText(pkg.version)).toBeVisible();
});
});
});

it("should render unauthorized when 401 error fetching packages", async () => {
Expand Down
6 changes: 4 additions & 2 deletions app/src/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,11 +842,13 @@ export const mockGitBranches: GitBranches = {
export const mockRunnerPackages: RunnerPackage[] = [
{
name: "package1",
version: "0.1.0"
version: "0.1.0",
location: "/library"
},
{
name: "package2",
version: "2.0.0"
version: "2.0.0",
location: "/usr/lib/R/library"
}
];

Expand Down
3 changes: 2 additions & 1 deletion app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ export interface Custom {
};
}

// R packages installed into a shared library for the runner and workers
// R packages installed for the runner and workers
export interface RunnerPackage {
name: string;
version: string;
location: string;
}

interface Description {
Expand Down
2 changes: 1 addition & 1 deletion scripts/common
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -exu

# Export env vars needed for running test dependencies
export OUTPACK_SERVER_IMAGE=docker.io/mrcide/outpack_server:main
export ORDERLY_RUNNER_IMAGE=ghcr.io/mrc-ide/orderly.runner:main
export ORDERLY_RUNNER_IMAGE=ghcr.io/mrc-ide/orderly.runner:library-list-report-all-packages
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this after the orderly.runner PR is merged, and before this is merged.

Suggested change
export ORDERLY_RUNNER_IMAGE=ghcr.io/mrc-ide/orderly.runner:library-list-report-all-packages
export ORDERLY_RUNNER_IMAGE=ghcr.io/mrc-ide/orderly.runner:main


export RUNNER_CONTAINER_NAMESPACE=orderly.runner
export RUNNER_REDIS=$RUNNER_CONTAINER_NAMESPACE-redis
Expand Down
Loading