Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ jobs:
mkdir -p $ZEPPELIN_E2E_TEST_NOTEBOOK_DIR
echo "Created test notebook directory: $ZEPPELIN_E2E_TEST_NOTEBOOK_DIR"
- name: Run headless E2E test with Maven
# Classic UI e2e runs only on the anonymous leg, like the legacy Protractor suite
run: xvfb-run --auto-servernum --server-args="-screen 0 1024x768x24" ./mvnw verify -pl zeppelin-web-angular -Pweb-e2e -Dweb.e2e.classic.disabled=${{ matrix.mode != 'anonymous' }} ${MAVEN_ARGS}
# Classic UI e2e and the notebook core port proof run only on the anonymous leg
run: xvfb-run --auto-servernum --server-args="-screen 0 1024x768x24" ./mvnw verify -pl zeppelin-web-angular -Pweb-e2e -Dweb.e2e.classic.disabled=${{ matrix.mode != 'anonymous' }} -Dweb.e2e.core.port.proof.disabled=${{ matrix.mode != 'anonymous' }} ${MAVEN_ARGS}
- name: Run revision isolation E2E test with Git storage
env:
CI: 'true'
Expand Down
46 changes: 46 additions & 0 deletions zeppelin-web-angular/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,52 @@
}
}
},
"notebook-core-port-proof": {
"root": "e2e/core-contract/angular-host",
"sourceRoot": "e2e/core-contract/angular-host",
"projectType": "application",
"prefix": "zeppelin",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/notebook-core-port-proof",
"index": "e2e/core-contract/angular-host/index.html",
"main": "e2e/core-contract/angular-host/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "e2e/core-contract/angular-host/tsconfig.json",
"assets": [
{
"glob": "**/*",
"input": "./e2e/core-contract/react-remote/dist",
"output": "/assets/react/"
}
],
"styles": [],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "none",
"sourceMap": false,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": false
}
},
"defaultConfiguration": "production"
}
}
},
"zeppelin-visualization": {
"projectType": "library",
"root": "projects/zeppelin-visualization",
Expand Down
29 changes: 29 additions & 0 deletions zeppelin-web-angular/e2e/core-contract/angular-host/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Notebook core port proof</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<zeppelin-notebook-core-port-proof></zeppelin-notebook-core-port-proof>
</body>
</html>
85 changes: 85 additions & 0 deletions zeppelin-web-angular/e2e/core-contract/angular-host/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { CommonModule } from '@angular/common';
import { Component, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { ReactMountDirective } from '@zeppelin/share/react-mount';
import type { NotebookCorePort, NotebookCoreSnapshot } from '@zeppelin/notebook-core';

declare global {
interface Window {
__zeppelinNotebookCorePortProof?: {
hostCore: NotebookCorePort;
proofs: unknown[];
receivedCore?: NotebookCorePort;
};
}
}

@Component({
selector: 'zeppelin-notebook-core-port-proof',
standalone: false,
template: `
<button type="button" data-testid="publish-notebook-core-revision" (click)="publishRevision()">
publish revision
</button>
<div [zeppelin-react-mount]="'./NotebookCorePortProbe'" [reactProps]="reactProps"></div>
`
})
export class NotebookCorePortProofComponent {
readonly core: NotebookCorePort = Object.freeze({
getSnapshot: () => this.snapshot,
subscribe: listener => {
this.listeners.add(listener);
return () => this.listeners.delete(listener);
}
});

readonly reactProps = {
core: this.core,
expectedCore: this.core,
onProof: (proof: unknown) => {
window.__zeppelinNotebookCorePortProof?.proofs.push(proof);
},
onReceivedCore: (receivedCore: NotebookCorePort) => {
window.__zeppelinNotebookCorePortProof!.receivedCore = receivedCore;
}
};

private snapshot: NotebookCoreSnapshot = { noteId: 'note-host-owned', revisionId: null };
private readonly listeners = new Set<() => void>();

constructor() {
window.__zeppelinNotebookCorePortProof = {
hostCore: this.core,
proofs: []
};
}

publishRevision(): void {
this.snapshot = { noteId: 'note-host-owned', revisionId: 'revision-from-angular-host' };
for (const listener of this.listeners) {
listener();
}
}
}

@NgModule({
bootstrap: [NotebookCorePortProofComponent],
declarations: [NotebookCorePortProofComponent, ReactMountDirective],
imports: [BrowserModule, CommonModule]
})
export class NotebookCorePortProofModule {}

void platformBrowserDynamic().bootstrapModule(NotebookCorePortProofModule);
13 changes: 13 additions & 0 deletions zeppelin-web-angular/e2e/core-contract/angular-host/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"ignoreDeprecations": "5.0",
"outDir": "../../../out-tsc/notebook-core-port-proof",
"types": []
},
"files": ["main.ts"],
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictTemplates": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import assert from 'node:assert/strict';
import { createReadStream, existsSync, statSync } from 'node:fs';
import { createServer } from 'node:http';
import { extname, isAbsolute, join, relative, resolve } from 'node:path';
import { after, before, test } from 'node:test';
import { pathToFileURL } from 'node:url';

import { chromium, expect } from '@playwright/test';

const angularDistRoot = resolve('dist/notebook-core-port-proof');
const angularIndexPath = join(angularDistRoot, 'index.html');
const remoteEntryPath = join(angularDistRoot, 'assets/react/remoteEntry.js');

let browser;
let server;
let baseUrl;

const contentTypes = new Map([
['.css', 'text/css; charset=utf-8'],
['.html', 'text/html; charset=utf-8'],
['.js', 'text/javascript; charset=utf-8']
]);

function resolveInsideAngularDist(requestPath) {
const decodedPath = decodeURIComponent(requestPath.replace(/^\//, ''));
const filePath = resolve(angularDistRoot, decodedPath);
const rootRelativePath = relative(angularDistRoot, filePath);

if (rootRelativePath.startsWith('..') || isAbsolute(rootRelativePath)) {
return null;
}

return filePath;
}

function isFile(filePath) {
return statSync(filePath, { throwIfNoEntry: false })?.isFile() ?? false;
}

function serveStaticFile(response, requestPath) {
const filePath = resolveInsideAngularDist(requestPath);

if (!filePath || !isFile(filePath)) {
response.writeHead(404);
response.end('not found');
return;
}

response.writeHead(200, {
'cache-control': 'no-store',
'content-type': contentTypes.get(extname(filePath)) ?? 'application/octet-stream'
});
createReadStream(filePath).pipe(response);
}

before(async () => {
assert.ok(
existsSync(angularIndexPath),
`Angular host build output is missing: run "npm run build:notebook-core-port-proof" before this proof (${pathToFileURL(
angularIndexPath
)})`
);
assert.ok(
existsSync(remoteEntryPath),
`React remote asset is missing: run "npm run build:notebook-core-port-proof" before this proof (${pathToFileURL(
remoteEntryPath
)})`
);

server = createServer((request, response) => {
const requestPath = request.url?.split('?')[0] ?? '/';
if (requestPath === '/') {
response.writeHead(200, {
'cache-control': 'no-store',
'content-type': 'text/html; charset=utf-8'
});
createReadStream(angularIndexPath).pipe(response);
return;
}

if (isFile(resolveInsideAngularDist(requestPath) ?? '')) {
serveStaticFile(response, requestPath);
return;
}

response.writeHead(404, { 'cache-control': 'no-store' });
response.end();
});

await new Promise(resolveListen => {
server.listen(0, '127.0.0.1', resolveListen);
});
const address = server.address();
assert.ok(address && typeof address === 'object');
baseUrl = `http://127.0.0.1:${address.port}`;
browser = await chromium.launch();
});

after(async () => {
await browser?.close();
await new Promise(resolveClose => server?.close(resolveClose));
});

test('React remote receives the exact host-owned NotebookCorePort object', async () => {
const page = await browser.newPage();

await page.goto(baseUrl);

const probe = page.getByTestId('notebook-core-port-probe');
await expect(probe).toHaveAttribute('data-same-identity', 'true', { timeout: 15_000 });
await expect(probe).toHaveAttribute('data-note-id', 'note-host-owned');
await expect(probe).toHaveAttribute('data-update-count', '0');

await page.waitForFunction(() => globalThis.__zeppelinNotebookCorePortProof?.receivedCore !== undefined);
const hostIdentity = await page.evaluate(() =>
Object.is(
globalThis.__zeppelinNotebookCorePortProof.hostCore,
globalThis.__zeppelinNotebookCorePortProof.receivedCore
)
);
assert.equal(hostIdentity, true);

await page.getByTestId('publish-notebook-core-revision').click();

await expect(probe).toHaveAttribute('data-revision-id', 'revision-from-angular-host');
await expect(probe).toHaveAttribute('data-update-count', '1');

await expect
.poll(() => page.evaluate(() => globalThis.__zeppelinNotebookCorePortProof.proofs.at(-1)))
.toEqual({
sameIdentity: true,
snapshot: { noteId: 'note-host-owned', revisionId: 'revision-from-angular-host' },
updateCount: 1
});

await page.close();
});
Loading
Loading