a215027c6b
* Add labs flag for sliding sync; add sliding_sync_proxy_url to config.json * Disable the labs toggle if sliding_sync_proxy_url is not set * Do validation checks on the sliding sync proxy URL before enabling it in Labs * Enable sliding sync and add SlidingSyncManager * Get room subscriptions working * Hijack renderSublists in sliding sync mode * Add support for sorting alphabetically/recency and room name filters * Filter out tombstoned rooms; start adding show more logic list ranges update but the UI doesn't * update the UI when the list is updated * bugfix: make sure the list sorts numerically * Get invites transitioning correctly * Force enable sliding sync and labs for now * Linting * Disable spotlight search * Initial cypress plugins for Sliding Sync Proxy * Use --rm when running Synapse in Docker for Cypress tests * Update src/MatrixClientPeg.ts Co-authored-by: Travis Ralston <travisr@matrix.org> * Update src/components/views/rooms/RoomSublist.tsx Co-authored-by: Travis Ralston <travisr@matrix.org> * Update src/settings/controllers/SlidingSyncController.ts Co-authored-by: Travis Ralston <travisr@matrix.org> * Update src/components/views/rooms/RoomSublist.tsx Co-authored-by: Travis Ralston <travisr@matrix.org> * WIP add room searching to spotlight search * Only read sliding sync results when there is a result, else use the local cache * Use feature_sliding_sync not slidingSync * Some review comments * More review comments * Use RoomViewStore to set room subscriptions * Comment why any * Update src/components/views/rooms/RoomSublist.tsx Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> * Fix cypress docker abstraction * Iterate sliding sync proxy support * Stash mostly functional test * Update sliding sync proxy image * i18n * Add support for spaces; use list ID -> index mappings - Mappings are more reusable and easier to understand than racing for index positions. - Register for all spaces immediately on startup. * When the active space is updated, update the list registration * Set spaces filter in the correct place * Skeleton placeholder whilst loading the space * Filter out spaces from the room list * Use the new txn_id promises * Ensure we actually resolve list registrations * Fix matrix-org/sliding-sync#30: don't show tombstoned search results * Remove unused imports * Add SYNCV3_SECRET to proxy to ensure it starts up; correct aliases for SS test * Add another basic sliding sync e2e test * Unbreak netlify * Add more logging for debugging duplicate rooms * If sliding sync is enabled, always use the rooms result even if it's empty * Drop-in copy of RoomListStore for sliding sync * Remove conditionals from RoomListStore - we have SlidingRoomListStore now * WIP SlidingRoomListStore * Add most sliding sync logic to SlidingRoomListStore Still lots of logic in RoomSublist. Broken things: - Join count is wrong completely. - No skeleton placeholder when switching spaces. * Migrate joined count to SS RLS * Reinstate the skeleton UI when the list is loading * linting * Add support for sticky rooms based on the currently active room * Add a bunch of passing SS E2E tests; some WIP * Unbreak build from git merge * Suppress unread indicators in sliding sync mode * Add regression test for https://github.com/matrix-org/sliding-sync/issues/28 * Add invite test flows; show the invite list The refactor to SS RLS removed the invite list entirely. * Remove show more click as it wasn't the bug * Linting and i18n * only enable SS by default on netlify * Jest fixes; merge conflict fixes; remove debug logging; use right sort enum values * Actually fix jest tests * Add support for favourites and low priority * Bump sliding sync version * Update sliding sync labs to be user configurable * delint * To disable SS or change proxy URL the user has to log out * Review comments * Linting * Apply suggestions from code review Co-authored-by: Travis Ralston <travisr@matrix.org> * Update src/stores/room-list/SlidingRoomListStore.ts Co-authored-by: Travis Ralston <travisr@matrix.org> * Review comments * Add issue link for TODO markers * Linting * Apply suggestions from code review Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> * More review comments * More review comments * stricter types Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: Travis Ralston <travisr@matrix.org>
188 lines
6.3 KiB
TypeScript
188 lines
6.3 KiB
TypeScript
/*
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
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.
|
|
*/
|
|
|
|
/// <reference types="cypress" />
|
|
|
|
import * as path from "path";
|
|
import * as os from "os";
|
|
import * as crypto from "crypto";
|
|
import * as fse from "fs-extra";
|
|
|
|
import PluginEvents = Cypress.PluginEvents;
|
|
import PluginConfigOptions = Cypress.PluginConfigOptions;
|
|
import { getFreePort } from "../utils/port";
|
|
import { dockerExec, dockerLogs, dockerRun, dockerStop } from "../docker";
|
|
|
|
// A cypress plugins to add command to start & stop synapses in
|
|
// docker with preset templates.
|
|
|
|
interface SynapseConfig {
|
|
configDir: string;
|
|
registrationSecret: string;
|
|
// Synapse must be configured with its public_baseurl so we have to allocate a port & url at this stage
|
|
baseUrl: string;
|
|
port: number;
|
|
}
|
|
|
|
export interface SynapseInstance extends SynapseConfig {
|
|
synapseId: string;
|
|
}
|
|
|
|
const synapses = new Map<string, SynapseInstance>();
|
|
|
|
function randB64Bytes(numBytes: number): string {
|
|
return crypto.randomBytes(numBytes).toString("base64").replace(/=*$/, "");
|
|
}
|
|
|
|
async function cfgDirFromTemplate(template: string): Promise<SynapseConfig> {
|
|
const templateDir = path.join(__dirname, "templates", template);
|
|
|
|
const stats = await fse.stat(templateDir);
|
|
if (!stats?.isDirectory) {
|
|
throw new Error(`No such template: ${template}`);
|
|
}
|
|
const tempDir = await fse.mkdtemp(path.join(os.tmpdir(), 'react-sdk-synapsedocker-'));
|
|
|
|
// copy the contents of the template dir, omitting homeserver.yaml as we'll template that
|
|
console.log(`Copy ${templateDir} -> ${tempDir}`);
|
|
await fse.copy(templateDir, tempDir, { filter: f => path.basename(f) !== 'homeserver.yaml' });
|
|
|
|
const registrationSecret = randB64Bytes(16);
|
|
const macaroonSecret = randB64Bytes(16);
|
|
const formSecret = randB64Bytes(16);
|
|
|
|
const port = await getFreePort();
|
|
const baseUrl = `http://localhost:${port}`;
|
|
|
|
// now copy homeserver.yaml, applying substitutions
|
|
console.log(`Gen ${path.join(templateDir, "homeserver.yaml")}`);
|
|
let hsYaml = await fse.readFile(path.join(templateDir, "homeserver.yaml"), "utf8");
|
|
hsYaml = hsYaml.replace(/{{REGISTRATION_SECRET}}/g, registrationSecret);
|
|
hsYaml = hsYaml.replace(/{{MACAROON_SECRET_KEY}}/g, macaroonSecret);
|
|
hsYaml = hsYaml.replace(/{{FORM_SECRET}}/g, formSecret);
|
|
hsYaml = hsYaml.replace(/{{PUBLIC_BASEURL}}/g, baseUrl);
|
|
await fse.writeFile(path.join(tempDir, "homeserver.yaml"), hsYaml);
|
|
|
|
// now generate a signing key (we could use synapse's config generation for
|
|
// this, or we could just do this...)
|
|
// NB. This assumes the homeserver.yaml specifies the key in this location
|
|
const signingKey = randB64Bytes(32);
|
|
console.log(`Gen ${path.join(templateDir, "localhost.signing.key")}`);
|
|
await fse.writeFile(path.join(tempDir, "localhost.signing.key"), `ed25519 x ${signingKey}`);
|
|
|
|
return {
|
|
port,
|
|
baseUrl,
|
|
configDir: tempDir,
|
|
registrationSecret,
|
|
};
|
|
}
|
|
|
|
// Start a synapse instance: the template must be the name of
|
|
// one of the templates in the cypress/plugins/synapsedocker/templates
|
|
// directory
|
|
async function synapseStart(template: string): Promise<SynapseInstance> {
|
|
const synCfg = await cfgDirFromTemplate(template);
|
|
|
|
console.log(`Starting synapse with config dir ${synCfg.configDir}...`);
|
|
|
|
const synapseId = await dockerRun({
|
|
image: "matrixdotorg/synapse:develop",
|
|
containerName: `react-sdk-cypress-synapse`,
|
|
params: [
|
|
"--rm",
|
|
"-v", `${synCfg.configDir}:/data`,
|
|
"-p", `${synCfg.port}:8008/tcp`,
|
|
],
|
|
cmd: "run",
|
|
});
|
|
|
|
console.log(`Started synapse with id ${synapseId} on port ${synCfg.port}.`);
|
|
|
|
// Await Synapse healthcheck
|
|
await dockerExec({
|
|
containerId: synapseId,
|
|
params: [
|
|
"curl",
|
|
"--connect-timeout", "30",
|
|
"--retry", "30",
|
|
"--retry-delay", "1",
|
|
"--retry-all-errors",
|
|
"--silent",
|
|
"http://localhost:8008/health",
|
|
],
|
|
});
|
|
|
|
const synapse: SynapseInstance = { synapseId, ...synCfg };
|
|
synapses.set(synapseId, synapse);
|
|
return synapse;
|
|
}
|
|
|
|
async function synapseStop(id: string): Promise<void> {
|
|
const synCfg = synapses.get(id);
|
|
|
|
if (!synCfg) throw new Error("Unknown synapse ID");
|
|
|
|
const synapseLogsPath = path.join("cypress", "synapselogs", id);
|
|
await fse.ensureDir(synapseLogsPath);
|
|
|
|
await dockerLogs({
|
|
containerId: id,
|
|
stdoutFile: path.join(synapseLogsPath, "stdout.log"),
|
|
stderrFile: path.join(synapseLogsPath, "stderr.log"),
|
|
});
|
|
|
|
await dockerStop({
|
|
containerId: id,
|
|
});
|
|
|
|
await fse.remove(synCfg.configDir);
|
|
|
|
synapses.delete(id);
|
|
|
|
console.log(`Stopped synapse id ${id}.`);
|
|
// cypress deliberately fails if you return 'undefined', so
|
|
// return null to signal all is well, and we've handled the task.
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @type {Cypress.PluginConfig}
|
|
*/
|
|
export function synapseDocker(on: PluginEvents, config: PluginConfigOptions) {
|
|
on("task", {
|
|
synapseStart,
|
|
synapseStop,
|
|
});
|
|
|
|
on("after:spec", async (spec) => {
|
|
// Cleans up any remaining synapse instances after a spec run
|
|
// This is on the theory that we should avoid re-using synapse
|
|
// instances between spec runs: they should be cheap enough to
|
|
// start that we can have a separate one for each spec run or even
|
|
// test. If we accidentally re-use synapses, we could inadvertently
|
|
// make our tests depend on each other.
|
|
for (const synId of synapses.keys()) {
|
|
console.warn(`Cleaning up synapse ID ${synId} after ${spec.name}`);
|
|
await synapseStop(synId);
|
|
}
|
|
});
|
|
|
|
on("before:run", async () => {
|
|
// tidy up old synapse log files before each run
|
|
await fse.emptyDir(path.join("cypress", "synapselogs"));
|
|
});
|
|
}
|